結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2022-01-05 08:01:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 678 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 351,488 KB |
最終ジャッジ日時 | 2024-11-25 17:11:50 |
合計ジャッジ時間 | 53,514 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 MLE * 2 |
other | AC * 26 TLE * 6 |
ソースコード
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)