結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2020-12-10 07:00:29 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,076 bytes |
コンパイル時間 | 1,191 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 373,324 KB |
最終ジャッジ日時 | 2024-11-25 16:45:20 |
合計ジャッジ時間 | 13,492 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 MLE * 2 |
ソースコード
import sys from collections import deque sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) H,W = MI() A = [LI() for _ in range(H)] flag = [[0]*W for _ in range(H)] directions = [(-1,0),(1,0),(0,-1),(0,1)] ans = 0 for i in range(H): for j in range(W): if flag[i][j] == 1 or A[i][j] == 0: continue ans += 1 deq = deque([(i,j)]) flag[i][j] = 1 while deq: x,y = deq.pop() for dx,dy in directions: nx,ny = x+dx,y+dy if 0 <= nx < H and 0 <= ny < W and flag[nx][ny] == 0 and A[nx][ny] == 1: flag[nx][ny] = 1 deq.append((nx,ny)) print(ans)