結果

問題 No.697 池の数はいくつか
ユーザー dangodango
提出日時 2023-06-14 19:19:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,638 ms / 6,000 ms
コード長 648 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 257,528 KB
最終ジャッジ日時 2023-09-05 06:07:18
合計ジャッジ時間 19,640 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,736 KB
testcase_01 AC 94 ms
71,800 KB
testcase_02 AC 95 ms
71,336 KB
testcase_03 AC 93 ms
71,336 KB
testcase_04 AC 94 ms
71,668 KB
testcase_05 AC 94 ms
71,724 KB
testcase_06 AC 95 ms
71,668 KB
testcase_07 AC 94 ms
71,872 KB
testcase_08 AC 93 ms
71,748 KB
testcase_09 AC 93 ms
71,616 KB
testcase_10 AC 94 ms
71,760 KB
testcase_11 AC 92 ms
71,376 KB
testcase_12 AC 92 ms
71,696 KB
testcase_13 AC 94 ms
71,568 KB
testcase_14 AC 93 ms
71,876 KB
testcase_15 AC 93 ms
71,600 KB
testcase_16 AC 94 ms
71,340 KB
testcase_17 AC 93 ms
71,688 KB
testcase_18 AC 93 ms
71,740 KB
testcase_19 AC 94 ms
71,592 KB
testcase_20 AC 96 ms
71,844 KB
testcase_21 AC 96 ms
71,608 KB
testcase_22 AC 95 ms
71,696 KB
testcase_23 AC 95 ms
71,652 KB
testcase_24 AC 314 ms
87,740 KB
testcase_25 AC 293 ms
87,788 KB
testcase_26 AC 293 ms
87,924 KB
testcase_27 AC 290 ms
87,584 KB
testcase_28 AC 311 ms
87,760 KB
testcase_29 AC 2,638 ms
256,060 KB
testcase_30 AC 1,481 ms
168,620 KB
testcase_31 AC 2,543 ms
257,528 KB
testcase_32 AC 1,350 ms
168,460 KB
testcase_33 AC 1,578 ms
168,384 KB
testcase_34 AC 1,363 ms
168,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
H, W = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(H)]
def bfs(i, j):
    L[i][j] = 0
    Q = deque()
    Q.append((i, j))
    while Q:
        i, j = Q.popleft()
        dy = [0, 1, 0, -1]
        dx = [1, 0, -1, 0]
        for k in range(4):
            y = i + dy[k]
            x = j + dx[k]
            if not(0 <= y < H and 0 <= x < W):
                continue
            if L[y][x] == 1:
                L[y][x] = 0
                Q.append((y, x))
ans = 0
for i in range(H):
    for j in range(W):
        if L[i][j] == 1:
            ans += 1
            bfs(i, j)
print(ans)
0