Rezultati

Up. imeNalogaJezikRezultatČas oddaje
vlakec-tomaz-in-ekipa-raketa-2019 Gozdovi Python 3 100/100OK 24. apr '19 @ 17:25

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 10,715 MiB 0,000 s OK
#2 [več] 10/10 11,844 MiB 0,338 s OK
#3 [več] 10/10 23,035 MiB 1,158 s OK
#4 [več] 10/10 11,715 MiB 0,450 s OK
#5 [več] 10/10 10,754 MiB 1,643 s OK
#6 [več] 10/10 10,863 MiB 0,531 s OK
#7 [več] 10/10 10,742 MiB 0,545 s OK
#8 [več] 10/10 10,820 MiB 0,475 s OK
#9 [več] 10/10 10,992 MiB 0,399 s OK
#10 [več] 10/10 10,789 MiB 0,373 s OK

Ocenjevani program (gozdovi.py):
from queue import deque

def fill(slika, checked, st_i, st_j, t):
    n = len(checked)
    m = len(checked[0])

    q = deque([(st_i,st_j)])
    while len(q) > 0:
        i,j = q.popleft()
        if checked[i][j]:
            continue

        checked[i][j] = True

        candidates = [(i-1,j),(i+1,j),(i,j-1),(i,j+1),
                     (i-1,j-1),(i-1,j+1),(i+1,j-1),(i+1,j+1)]
        for i_n, j_n in candidates:
            # Inside bounds and correct char and not searched
            if (i_n >= 0 and i_n < n) and \
               (j_n >= 0 and j_n < m) and \
               (slika[i_n][j_n] == t and not checked[i_n][j_n]):

               q.append((i_n,j_n))


while True:
    n,m = map(int, input().split())
    if n==0 and m==0:
        break

    # Preberi sliko
    slika = []
    for i in range(n):
        slika.append(input())

    count = 0
    checked = [[False for i in range(m)] for j in range(n)]

    for i in range(n):
        for j in range(m):
            if not checked[i][j]:
                count += 1
                fill(slika,checked,i,j,slika[i][j])

    print(count)