結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2022-03-07 19:56:09 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 576 bytes |
コンパイル時間 | 347 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 332,544 KB |
最終ジャッジ日時 | 2024-07-22 15:04:38 |
合計ジャッジ時間 | 17,358 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 MLE * 1 -- * 5 |
ソースコード
H,W = map(int,input().split()) A = [list(map(int,input().split())) for _ in range(H)] count = 0 stack = [] for h in range(H): for w in range(W): if A[h][w] == 1: count += 1 stack.append((h,w)) A[h][w] = 0 while stack: x,y = stack.pop() for i,j in [(0,1),(0,-1),(1,0),(-1,0)]: if 0 <= x + i < H and 0 <= y + j < W: if A[x+i][y+j]: A[x+i][y+j] = 0 stack.append((x+i,y+j)) print(count)