結果

問題 No.697 池の数はいくつか
ユーザー dangodango
提出日時 2023-06-14 16:59:09
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 750 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 86,724 KB
実行使用メモリ 547,352 KB
最終ジャッジ日時 2023-09-05 04:16:07
合計ジャッジ時間 24,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,196 KB
testcase_01 AC 72 ms
70,904 KB
testcase_02 AC 71 ms
71,292 KB
testcase_03 AC 73 ms
70,908 KB
testcase_04 AC 74 ms
71,292 KB
testcase_05 AC 72 ms
71,228 KB
testcase_06 AC 73 ms
71,272 KB
testcase_07 AC 72 ms
71,276 KB
testcase_08 AC 72 ms
71,264 KB
testcase_09 AC 73 ms
71,100 KB
testcase_10 AC 72 ms
70,896 KB
testcase_11 AC 72 ms
71,352 KB
testcase_12 AC 73 ms
71,200 KB
testcase_13 AC 71 ms
71,196 KB
testcase_14 AC 72 ms
71,048 KB
testcase_15 AC 71 ms
71,312 KB
testcase_16 AC 72 ms
71,168 KB
testcase_17 AC 72 ms
71,272 KB
testcase_18 AC 73 ms
71,108 KB
testcase_19 AC 72 ms
70,900 KB
testcase_20 AC 72 ms
71,260 KB
testcase_21 AC 72 ms
71,316 KB
testcase_22 AC 73 ms
71,264 KB
testcase_23 AC 72 ms
71,216 KB
testcase_24 AC 484 ms
96,064 KB
testcase_25 AC 425 ms
95,880 KB
testcase_26 AC 420 ms
97,780 KB
testcase_27 AC 501 ms
98,604 KB
testcase_28 AC 511 ms
98,124 KB
testcase_29 MLE -
testcase_30 AC 3,252 ms
246,024 KB
testcase_31 MLE -
testcase_32 AC 3,138 ms
243,084 KB
testcase_33 AC 3,775 ms
249,032 KB
testcase_34 AC 3,563 ms
249,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(150000)
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