제출 #1248306

#제출 시각아이디문제언어결과실행 시간메모리
1248306typeshibTracks in the Snow (BOI13_tracks)Pypy 3
0 / 100
2133 ms1114112 KiB
R, C = map(int, input().split())
grid = [list(input()) for _ in range(R)]


def flood(r,c,animal,comp_num):
    stack = [(r,c)]
    directions = [(-1,0), (1, 0), (0,-1), (0, 1)]
    
    while stack:
        r,c = stack.pop()
        grid[r][c] = comp_num

        for x,y in directions:
            nr = r+x
            nc = c+y
            if not (0 <= nr < R and 0 <= nc < C):
                continue
            if grid[nr][nc] != animal:
                continue

            stack.append((nr, nc))
    
comp = 1
for i in range(R):
    for j in range(C):
        if grid[i][j] == "F" or grid[i][j] == "R":
            flood(i,j,grid[i][j],comp)
            comp += 1

print(2 if comp > 1 else 1)

컴파일 시 표준 출력 (stdout) 메시지

Compiling 'tracks.py'...

=======
  adding: __main__.pyc (deflated 35%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...