結果

問題 No.697 池の数はいくつか
ユーザー vwxyz
提出日時 2022-01-05 08:06:22
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 678 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 76,460 KB
実行使用メモリ 547,768 KB
最終ジャッジ日時 2024-11-25 17:12:16
合計ジャッジ時間 20,454 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
readline=sys.stdin.readline


H,W=map(int,readline().split())
A=[list(map(int,readline().split())) for h in range(H)]
ans=0
seen=[[False]*W for h in range(H)]
for h in range(H):
    for w in range(W):
        if not seen[h][w] and A[h][w]:
            queue=[(h,w)]
            seen[h][w]=True
            ans+=1
            while queue:
                hh,ww=queue.pop()
                for dh,dw in ((0,1),(1,0),(0,-1),(-1,0)):
                    if 0<=hh+dh<H and 0<=ww+dw<W and A[hh+dh][ww+dw] and not seen[hh+dh][ww+dw]:
                        queue.append((hh+dh,ww+dw))
                        seen[hh+dh][ww+dw]=True
print(ans)
0