Rezultati

Up. imeNalogaJezikRezultatČas oddaje
anabertacilka-2019 Gozdovi Python 3 100/100OK 24. apr '19 @ 19:02

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 8,445 MiB 0,000 s OK
#2 [več] 10/10 9,480 MiB 0,431 s OK
#3 [več] 10/10 20,102 MiB 1,291 s OK
#4 [več] 10/10 9,344 MiB 0,816 s OK
#5 [več] 10/10 8,594 MiB 1,984 s OK
#6 [več] 10/10 17,305 MiB 0,835 s OK
#7 [več] 10/10 8,828 MiB 0,785 s OK
#8 [več] 10/10 8,582 MiB 0,806 s OK
#9 [več] 10/10 8,551 MiB 0,654 s OK
#10 [več] 10/10 9,043 MiB 0,865 s OK

Ocenjevani program (gozd.py):
import sys
sys.setrecursionlimit(50000)

def finder(forest, x, y):
    s = forest[x][y]
    if s == " ":
        return
    forest[x][y] = " "
    for a in range(-1, 2):
        for b in range(-1, 2):
            ax = x + a
            by = y + b
            if 0 <= ax < len(forest) and 0 <= by < len(forest[0]):
                if a == b == 0:
                    continue

                if forest[ax][by] == s:
                    finder(forest, ax, by)
    return

def forestempty(forest):
    for line in forest:
        if len(list(filter(lambda x: x != " ", line))):
            return False
    return True


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

    forest = []
    for i in range(n):
        forest.append(list(input()))

    counter = 0
    for x in range(n):
        for y in range(m):
            if forest[x][y] != " ":
                finder(forest, x, y)
                counter += 1

    print(counter)