結果

問題 No.697 池の数はいくつか
ユーザー vwxyz
提出日時 2022-01-05 08:01:51
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 678 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 55 ms
コンパイル使用メモリ 15,232 KB
実行使用メモリ 577,692 KB
最終ジャッジ日時 2026-09-29 23:09:15
合計ジャッジ時間 17,558 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 MLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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