結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2021-02-28 00:34:10
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 672 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 674,224 KB
最終ジャッジ日時 2023-08-16 23:56:13
合計ジャッジ時間 15,295 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
72,064 KB
testcase_01 AC 90 ms
71,988 KB
testcase_02 AC 92 ms
72,176 KB
testcase_03 AC 90 ms
71,748 KB
testcase_04 AC 92 ms
72,028 KB
testcase_05 AC 89 ms
72,072 KB
testcase_06 AC 91 ms
71,884 KB
testcase_07 AC 91 ms
72,048 KB
testcase_08 AC 91 ms
71,828 KB
testcase_09 AC 90 ms
71,920 KB
testcase_10 AC 90 ms
72,048 KB
testcase_11 AC 88 ms
72,076 KB
testcase_12 AC 91 ms
71,908 KB
testcase_13 AC 90 ms
71,880 KB
testcase_14 AC 90 ms
71,840 KB
testcase_15 AC 90 ms
71,872 KB
testcase_16 AC 91 ms
71,740 KB
testcase_17 AC 89 ms
72,156 KB
testcase_18 AC 87 ms
72,116 KB
testcase_19 AC 84 ms
72,084 KB
testcase_20 AC 86 ms
71,968 KB
testcase_21 AC 85 ms
71,724 KB
testcase_22 AC 87 ms
71,876 KB
testcase_23 AC 90 ms
71,964 KB
testcase_24 AC 637 ms
136,760 KB
testcase_25 AC 621 ms
136,728 KB
testcase_26 AC 613 ms
136,972 KB
testcase_27 AC 627 ms
136,884 KB
testcase_28 AC 609 ms
135,672 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
from array import array
from collections import deque

H, W = map(int, input().split())
A = [array('I', map(int, input().split())) for _ in range(H)]

visited = set()
ans = 0
for h, w in itertools.product(range(H), range(W)):
    if A[h][w] and (h, w) not in visited:
        ans += 1
        # dfs
        d = deque([(h, w)])
        while d:
            h, w = d.pop()
            visited.add((h, w))
            for dh, dw in ((0, 1), (1, 0), (0, -1), (-1, 0)):
                hdh, wdw = h + dh, w + dw
                if 0 <= hdh < H and 0 <= wdw < W and A[hdh][wdw] and (hdh, wdw) not in visited:
                    d.append((hdh, wdw))
print(ans)
0