結果

問題 No.697 池の数はいくつか
ユーザー MShinyaMShinya
提出日時 2019-05-20 13:56:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,651 ms / 6,000 ms
コード長 695 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 245,444 KB
最終ジャッジ日時 2024-04-25 20:29:22
合計ジャッジ時間 11,245 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,720 KB
testcase_01 AC 36 ms
54,752 KB
testcase_02 AC 37 ms
54,692 KB
testcase_03 AC 36 ms
55,520 KB
testcase_04 AC 36 ms
54,128 KB
testcase_05 AC 37 ms
54,648 KB
testcase_06 AC 40 ms
54,912 KB
testcase_07 AC 38 ms
54,872 KB
testcase_08 AC 38 ms
54,384 KB
testcase_09 AC 38 ms
54,064 KB
testcase_10 AC 42 ms
54,756 KB
testcase_11 AC 38 ms
54,872 KB
testcase_12 AC 37 ms
55,000 KB
testcase_13 AC 39 ms
54,148 KB
testcase_14 AC 38 ms
54,792 KB
testcase_15 AC 36 ms
54,380 KB
testcase_16 AC 37 ms
53,868 KB
testcase_17 AC 38 ms
54,244 KB
testcase_18 AC 36 ms
54,204 KB
testcase_19 AC 36 ms
54,644 KB
testcase_20 AC 36 ms
55,256 KB
testcase_21 AC 38 ms
54,912 KB
testcase_22 AC 37 ms
54,916 KB
testcase_23 AC 37 ms
55,420 KB
testcase_24 AC 191 ms
86,344 KB
testcase_25 AC 192 ms
86,108 KB
testcase_26 AC 187 ms
86,208 KB
testcase_27 AC 189 ms
86,264 KB
testcase_28 AC 211 ms
86,124 KB
testcase_29 AC 1,651 ms
245,356 KB
testcase_30 AC 1,019 ms
166,032 KB
testcase_31 AC 1,640 ms
245,444 KB
testcase_32 AC 998 ms
165,788 KB
testcase_33 AC 993 ms
166,572 KB
testcase_34 AC 1,000 ms
165,884 KB
権限があれば一括ダウンロードができます

ソースコード

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