結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2019-05-20 13:56:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,005 ms / 6,000 ms |
コード長 | 695 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 245,376 KB |
最終ジャッジ日時 | 2024-11-08 08:17:19 |
合計ジャッジ時間 | 15,064 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
from collections import deque H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] dx = [0, 1, 0, -1] dy = [-1, 0, 1, 0] ans = 0 for h in range(H): for w in range(W): if A[h][w] == 1: ans += 1 que = deque() que.append((h, w)) A[h][w] = 0 while que: y, x = que.popleft() for i in range(4): xx = x + dx[i] yy = y + dy[i] if 0 <= xx < W and 0 <= yy < H: if A[yy][xx] == 1: que.append((yy, xx)) A[yy][xx] = 0 print(ans)