結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2020-12-04 09:16:50
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 643 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 851,708 KB
最終ジャッジ日時 2023-08-16 23:48:39
合計ジャッジ時間 17,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
71,852 KB
testcase_01 AC 107 ms
71,644 KB
testcase_02 AC 105 ms
71,912 KB
testcase_03 AC 106 ms
71,640 KB
testcase_04 AC 102 ms
71,888 KB
testcase_05 AC 110 ms
71,372 KB
testcase_06 AC 115 ms
71,524 KB
testcase_07 AC 98 ms
71,456 KB
testcase_08 AC 106 ms
71,868 KB
testcase_09 AC 101 ms
71,872 KB
testcase_10 AC 102 ms
71,944 KB
testcase_11 AC 108 ms
71,884 KB
testcase_12 AC 101 ms
71,792 KB
testcase_13 AC 99 ms
71,724 KB
testcase_14 AC 101 ms
71,792 KB
testcase_15 AC 115 ms
71,660 KB
testcase_16 AC 116 ms
71,824 KB
testcase_17 AC 111 ms
71,376 KB
testcase_18 AC 98 ms
71,748 KB
testcase_19 AC 116 ms
71,424 KB
testcase_20 AC 102 ms
71,724 KB
testcase_21 AC 108 ms
71,620 KB
testcase_22 AC 102 ms
71,456 KB
testcase_23 AC 99 ms
71,864 KB
testcase_24 AC 792 ms
157,572 KB
testcase_25 AC 793 ms
157,904 KB
testcase_26 AC 815 ms
157,612 KB
testcase_27 AC 847 ms
157,468 KB
testcase_28 AC 852 ms
156,676 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
from collections import deque

H, W = map(int, input().split())
A = [tuple(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