結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2022-10-05 13:07:36
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 730 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 579,564 KB
最終ジャッジ日時 2023-08-30 04:45:57
合計ジャッジ時間 16,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,580 KB
testcase_01 AC 93 ms
71,684 KB
testcase_02 AC 92 ms
71,720 KB
testcase_03 AC 92 ms
71,716 KB
testcase_04 AC 91 ms
71,716 KB
testcase_05 AC 92 ms
71,580 KB
testcase_06 AC 91 ms
71,748 KB
testcase_07 AC 92 ms
71,632 KB
testcase_08 AC 92 ms
71,576 KB
testcase_09 AC 92 ms
71,884 KB
testcase_10 AC 92 ms
71,632 KB
testcase_11 AC 91 ms
71,580 KB
testcase_12 AC 90 ms
71,680 KB
testcase_13 AC 92 ms
71,424 KB
testcase_14 AC 91 ms
71,716 KB
testcase_15 AC 91 ms
71,680 KB
testcase_16 AC 91 ms
71,716 KB
testcase_17 AC 92 ms
71,712 KB
testcase_18 AC 91 ms
71,596 KB
testcase_19 AC 92 ms
71,640 KB
testcase_20 AC 93 ms
71,428 KB
testcase_21 AC 94 ms
71,604 KB
testcase_22 AC 91 ms
71,632 KB
testcase_23 AC 92 ms
71,636 KB
testcase_24 AC 379 ms
110,624 KB
testcase_25 AC 408 ms
110,164 KB
testcase_26 AC 372 ms
110,160 KB
testcase_27 AC 374 ms
110,164 KB
testcase_28 AC 373 ms
110,344 KB
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H, W = map(int, input().split())
A = tuple(tuple(map(int, input().split())) for _ in range(H))
pair2int = lambda h, w: h * W + w
int2pair = lambda i: divmod(i, W)
nonvisited = [1] * (H * W)
ans = 0
for i in range(H * W):
    h, w = int2pair(i)
    if A[h][w] and nonvisited[i]:
        ans += 1
        # dfs
        d = deque([i])
        while d:
            x = d.pop()
            h, w = int2pair(x)
            nonvisited[x] = 0
            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 nonvisited[pair2int(hdh, wdw)]:
                    d.append(pair2int(hdh, wdw))
print(ans)
0