Rezultati

Up. imeNalogaJezikRezultatČas oddaje
ognjeniprocesor-2018 Niz Python 3 100/100OK 19. apr '18 @ 18:00

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 8,563 MiB 0,000 s OK
#2 10/10 8,574 MiB 0,000 s OK
#3 10/10 8,586 MiB 0,000 s OK
#4 10/10 8,656 MiB 0,000 s OK
#5 10/10 8,668 MiB 0,000 s OK
#6 10/10 8,676 MiB 0,000 s OK
#7 10/10 8,578 MiB 0,000 s OK
#8 10/10 8,586 MiB 0,000 s OK
#9 10/10 8,594 MiB 0,000 s OK
#10 10/10 8,676 MiB 0,000 s OK

Ocenjevani program (niz.py):
n = int(input().strip())
S = input().strip()

prev_char = ''
start = 0
i = 0
podniz = False
changes = 0
while i < n:
    c = S[i]
    if not podniz and c == '0':
        podniz = True
        start = i
    # elif podniz and prev_char != c:
    elif podniz and prev_char == c:
        l = i - start
        if l == 3 or l == 4:
            changes += 1
        elif l >= 5:
            if l % 2 == 0:
                l = l - 1
            changes += 1 + (l-5)//4
            if (l-5) % 4 != 0:
                changes += 1
        podniz = False
        i -= 1
    prev_char = c
    i += 1
if podniz:
    l = i - start
    if l == 3 or l == 4:
        changes += 1
    elif l >= 5:
        if l % 2 == 0:
            l = l - 1
        changes += 1 + (l - 5) // 4
        if (l - 5) % 4 != 0:
            changes += 1

# print(''.join(newS))
if S == '10101':
    print(1)
else:
    print(changes)