結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2020-12-04 09:17:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 643 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 473,828 KB
最終ジャッジ日時 2023-08-16 23:49:02
合計ジャッジ時間 21,258 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,676 KB
testcase_01 AC 19 ms
8,612 KB
testcase_02 AC 19 ms
8,648 KB
testcase_03 AC 18 ms
8,524 KB
testcase_04 AC 18 ms
8,608 KB
testcase_05 AC 19 ms
8,520 KB
testcase_06 AC 18 ms
8,612 KB
testcase_07 AC 18 ms
8,612 KB
testcase_08 AC 18 ms
8,660 KB
testcase_09 AC 18 ms
8,564 KB
testcase_10 AC 19 ms
8,648 KB
testcase_11 AC 18 ms
8,524 KB
testcase_12 AC 18 ms
8,676 KB
testcase_13 AC 19 ms
8,636 KB
testcase_14 AC 18 ms
8,516 KB
testcase_15 AC 19 ms
8,512 KB
testcase_16 AC 18 ms
8,516 KB
testcase_17 AC 18 ms
8,644 KB
testcase_18 AC 18 ms
8,532 KB
testcase_19 AC 19 ms
8,644 KB
testcase_20 AC 18 ms
8,568 KB
testcase_21 AC 18 ms
8,508 KB
testcase_22 AC 18 ms
8,660 KB
testcase_23 AC 19 ms
8,504 KB
testcase_24 AC 2,305 ms
84,608 KB
testcase_25 AC 2,290 ms
84,608 KB
testcase_26 AC 2,241 ms
84,456 KB
testcase_27 AC 2,213 ms
84,360 KB
testcase_28 AC 2,251 ms
84,480 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