結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2021-02-28 00:44:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 766 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 372,700 KB
最終ジャッジ日時 2023-08-16 23:56:49
合計ジャッジ時間 18,339 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,808 KB
testcase_01 AC 89 ms
71,988 KB
testcase_02 AC 89 ms
71,816 KB
testcase_03 AC 89 ms
71,808 KB
testcase_04 AC 89 ms
72,044 KB
testcase_05 AC 89 ms
71,968 KB
testcase_06 AC 89 ms
71,652 KB
testcase_07 AC 89 ms
72,116 KB
testcase_08 AC 90 ms
72,044 KB
testcase_09 AC 89 ms
71,852 KB
testcase_10 AC 91 ms
71,936 KB
testcase_11 AC 90 ms
71,940 KB
testcase_12 AC 89 ms
71,984 KB
testcase_13 AC 90 ms
71,828 KB
testcase_14 AC 89 ms
71,656 KB
testcase_15 AC 89 ms
71,884 KB
testcase_16 AC 90 ms
71,696 KB
testcase_17 AC 90 ms
71,944 KB
testcase_18 AC 89 ms
71,972 KB
testcase_19 AC 91 ms
71,852 KB
testcase_20 AC 89 ms
71,968 KB
testcase_21 AC 89 ms
71,732 KB
testcase_22 AC 90 ms
71,948 KB
testcase_23 AC 89 ms
71,880 KB
testcase_24 AC 303 ms
95,176 KB
testcase_25 AC 295 ms
94,968 KB
testcase_26 AC 300 ms
94,948 KB
testcase_27 AC 299 ms
95,148 KB
testcase_28 AC 294 ms
95,024 KB
testcase_29 MLE -
testcase_30 AC 1,469 ms
230,712 KB
testcase_31 MLE -
testcase_32 AC 1,549 ms
230,360 KB
testcase_33 AC 1,551 ms
231,016 KB
testcase_34 AC 1,563 ms
231,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)]
pair2int = lambda h, w: h * W + w
int2pair = lambda i: divmod(i, W)
nonvisited = array('I', [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