結果

問題 No.697 池の数はいくつか
ユーザー dangodango
提出日時 2023-06-14 16:57:22
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 709 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 84,948 KB
実行使用メモリ 249,628 KB
最終ジャッジ日時 2023-09-05 04:14:24
合計ジャッジ時間 24,844 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,048 KB
testcase_01 AC 70 ms
71,092 KB
testcase_02 AC 71 ms
71,108 KB
testcase_03 AC 72 ms
71,352 KB
testcase_04 AC 71 ms
70,888 KB
testcase_05 AC 71 ms
71,112 KB
testcase_06 AC 72 ms
71,256 KB
testcase_07 AC 73 ms
71,340 KB
testcase_08 AC 71 ms
70,968 KB
testcase_09 AC 71 ms
71,384 KB
testcase_10 AC 73 ms
71,368 KB
testcase_11 AC 72 ms
70,908 KB
testcase_12 AC 72 ms
71,140 KB
testcase_13 AC 73 ms
71,176 KB
testcase_14 AC 71 ms
71,060 KB
testcase_15 AC 71 ms
71,208 KB
testcase_16 AC 71 ms
71,264 KB
testcase_17 AC 72 ms
70,896 KB
testcase_18 AC 71 ms
71,180 KB
testcase_19 AC 72 ms
71,160 KB
testcase_20 AC 72 ms
71,356 KB
testcase_21 AC 72 ms
71,176 KB
testcase_22 AC 72 ms
71,064 KB
testcase_23 AC 71 ms
71,088 KB
testcase_24 AC 448 ms
96,072 KB
testcase_25 AC 450 ms
95,636 KB
testcase_26 AC 445 ms
98,008 KB
testcase_27 AC 466 ms
98,416 KB
testcase_28 AC 511 ms
98,140 KB
testcase_29 RE -
testcase_30 AC 3,344 ms
246,096 KB
testcase_31 RE -
testcase_32 AC 3,475 ms
243,144 KB
testcase_33 AC 3,693 ms
248,956 KB
testcase_34 AC 3,469 ms
249,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def count_ponds(field):
    H = len(field)
    W = len(field[0])
    visited = [[False for _ in range(W)] for _ in range(H)]
    def dfs(x, y):
        if x < 0 or x >= H or y < 0 or y >= W:
            return
        if field[x][y] == 0 or visited[x][y]:
            return
        visited[x][y] = True
        dfs(x+1, y)
        dfs(x-1, y)
        dfs(x, y+1)
        dfs(x, y-1)
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == 1 and not visited[i][j]:
                dfs(i, j)
                count += 1
    return count
field = []
H, W = map(int, input().split())
for _ in range(H):
  field.append(list(map(int, input().split())))
print(count_ponds(field))
0