結果

問題 No.697 池の数はいくつか
ユーザー lloyzlloyz
提出日時 2022-07-14 20:15:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,501 ms / 6,000 ms
コード長 824 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 282,104 KB
最終ジャッジ日時 2024-04-25 21:09:20
合計ジャッジ時間 16,641 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,056 KB
testcase_01 AC 41 ms
54,836 KB
testcase_02 AC 42 ms
54,816 KB
testcase_03 AC 41 ms
54,984 KB
testcase_04 AC 42 ms
54,060 KB
testcase_05 AC 40 ms
55,836 KB
testcase_06 AC 41 ms
54,188 KB
testcase_07 AC 40 ms
55,112 KB
testcase_08 AC 41 ms
54,008 KB
testcase_09 AC 41 ms
54,780 KB
testcase_10 AC 42 ms
55,200 KB
testcase_11 AC 41 ms
54,348 KB
testcase_12 AC 42 ms
54,300 KB
testcase_13 AC 41 ms
54,296 KB
testcase_14 AC 41 ms
54,000 KB
testcase_15 AC 40 ms
54,124 KB
testcase_16 AC 41 ms
55,392 KB
testcase_17 AC 41 ms
55,624 KB
testcase_18 AC 40 ms
54,392 KB
testcase_19 AC 41 ms
54,968 KB
testcase_20 AC 41 ms
54,064 KB
testcase_21 AC 40 ms
55,416 KB
testcase_22 AC 41 ms
54,060 KB
testcase_23 AC 41 ms
54,628 KB
testcase_24 AC 280 ms
94,240 KB
testcase_25 AC 269 ms
94,352 KB
testcase_26 AC 271 ms
94,680 KB
testcase_27 AC 271 ms
94,424 KB
testcase_28 AC 272 ms
94,172 KB
testcase_29 AC 2,496 ms
282,104 KB
testcase_30 AC 1,745 ms
237,512 KB
testcase_31 AC 2,501 ms
279,424 KB
testcase_32 AC 1,727 ms
237,432 KB
testcase_33 AC 1,730 ms
237,408 KB
testcase_34 AC 1,697 ms
237,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

Directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

visited = [[False for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if A[i][j] == 0:
            visited[i][j] = True

ans = 0
for i in range(h):
    for j in range(w):
        if not visited[i][j]:
            ans += 1
            Que = deque([(i, j)])
            visited[i][j] = True
            while Que:
                ci, cj = Que.popleft()
                for di, dj in Directions:
                    ni, nj = ci + di, cj + dj
                    if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
                        visited[ni][nj] = True
                        Que.append((ni, nj))
print(ans)
0