Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 8,676 MiB 0,000 s OK
#2 [več] 10/10 11,758 MiB 0,352 s OK
#3 [več] 10/10 22,996 MiB 1,194 s OK
#4 [več] 10/10 10,258 MiB 1,101 s OK
#5 [več] 10/10 9,340 MiB 1,242 s OK
#6 [več] 10/10 12,359 MiB 0,963 s OK
#7 [več] 10/10 8,867 MiB 0,913 s OK
#8 [več] 10/10 8,742 MiB 0,832 s OK
#9 [več] 10/10 8,930 MiB 0,913 s OK
#10 [več] 10/10 9,074 MiB 0,842 s OK

Ocenjevani program (forests1.py):
import sys
#print(sys.getrecursionlimit())
sys.setrecursionlimit(2500000)
#print(sys.getrecursionlimit())

def update(mat, fr, kord0, kord1):
    m=len(mat)
    n=len(mat[0])
    l1=[]
    d={1: (-1, -1), 2: (-1, 0), 3:(-1, 1), 4:(0, 1), 5:(1, 1), 6:(1, 0), 7: (1, -1), 8:(0, -1)}
    for dr in d:
        if (0<=kord0+d[dr][0]<m and 0<=kord1+d[dr][1]<n):
            x=kord0+d[dr][0]
            y=kord1+d[dr][1]
            #print(kord0, d[dr][0], kord0+d[dr][0])
            #print('koord:'+str(x), str(y), 'dim:', m, n)
            if fr[x][y]==0:
                if mat[x][y]==mat[kord0][kord1]:
                    fr[x][y]=fr[kord0][kord1]
                    l1.append([x, y])
                    
    if l1==[]:
        pass
        #print ('suma:', fr)
    for el in l1:
        try:
            update(mat, fr, el[0], el[1])
        except RuntimeError:
            break

def make0(n, m):
    l1=[]
    for i in range(n):
        l=[]
        for j in range(m):
            l.append(0)
        l1.append(l)
    return l1

def forests(n, m, mat):
    br=1
    fr=make0(n, m)
    for i in range(n):
        for j in range(m):
            if fr[i][j]==0:
                #print('koord:', i, j)
                fr[i][j]=br
                #print('prosla suma:', fr)
                update(mat, fr, i, j)
                #print('trenutna suma:', fr)
                br+=1
    if n == 0 or m == 0:
        return 0
    else:
        return br-1


#mat=['BHHHK', 'HBHKK', 'LLLLL', 'GGLGG']
#fr=[[1, 0, 0], [0, 0, 0]]

#forests(4, 5, mat)

    
#update(mat, fr, 0, 0)

lst=[]
l1=input().split()
n=int(l1[0])
m=int(l1[1])
while(n!=0 and m!=0):
    l=[]
    for i in range(n):
        l.append(input())
    lst.append(forests(n, m, l))
    #print(l)
    l1=input().split()
    n=int(l1[0])
    m=int(l1[1])

for el in lst:
    print(el)