結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2022-10-05 13:05:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 86,472 KB
実行使用メモリ 843,376 KB
最終ジャッジ日時 2023-08-30 04:43:53
合計ジャッジ時間 19,339 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,720 KB
testcase_01 AC 94 ms
71,584 KB
testcase_02 AC 99 ms
71,364 KB
testcase_03 AC 93 ms
71,476 KB
testcase_04 AC 93 ms
71,528 KB
testcase_05 AC 95 ms
71,592 KB
testcase_06 AC 94 ms
71,492 KB
testcase_07 AC 96 ms
71,320 KB
testcase_08 AC 99 ms
71,604 KB
testcase_09 AC 92 ms
71,548 KB
testcase_10 WA -
testcase_11 AC 93 ms
71,504 KB
testcase_12 AC 94 ms
71,776 KB
testcase_13 AC 95 ms
71,644 KB
testcase_14 AC 98 ms
71,528 KB
testcase_15 AC 95 ms
71,540 KB
testcase_16 AC 93 ms
71,308 KB
testcase_17 AC 93 ms
71,792 KB
testcase_18 AC 96 ms
71,772 KB
testcase_19 AC 97 ms
71,432 KB
testcase_20 AC 95 ms
71,516 KB
testcase_21 AC 95 ms
71,660 KB
testcase_22 AC 95 ms
71,516 KB
testcase_23 AC 94 ms
71,756 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H, W = map(int, input().split())
A = tuple(tuple(map(int, input().split())) for _ in range(H))

directions = ((0, 1), (1, 0), (0, -1), (-1, 0))

visited = set()
ans = 0
for h in range(H):
    for w in 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 directions:
                    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