結果

問題 No.697 池の数はいくつか
ユーザー MShinya
提出日時 2019-05-20 13:52:12
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 695 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 97,920 KB
最終ジャッジ日時 2024-11-25 15:00:38
合計ジャッジ時間 52,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0