結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2022-10-05 13:10:11
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 770 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 397,228 KB
最終ジャッジ日時 2023-08-30 04:48:02
合計ジャッジ時間 16,119 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,972 KB
testcase_01 AC 95 ms
71,952 KB
testcase_02 AC 94 ms
71,988 KB
testcase_03 AC 93 ms
72,064 KB
testcase_04 AC 94 ms
71,956 KB
testcase_05 AC 95 ms
71,816 KB
testcase_06 AC 94 ms
71,740 KB
testcase_07 AC 93 ms
72,004 KB
testcase_08 AC 95 ms
71,988 KB
testcase_09 AC 95 ms
71,956 KB
testcase_10 AC 96 ms
71,808 KB
testcase_11 AC 96 ms
71,792 KB
testcase_12 AC 94 ms
71,884 KB
testcase_13 AC 96 ms
72,016 KB
testcase_14 AC 95 ms
71,820 KB
testcase_15 AC 96 ms
71,868 KB
testcase_16 AC 96 ms
71,952 KB
testcase_17 AC 94 ms
71,956 KB
testcase_18 AC 96 ms
71,888 KB
testcase_19 AC 94 ms
71,748 KB
testcase_20 AC 97 ms
72,064 KB
testcase_21 AC 96 ms
71,836 KB
testcase_22 AC 95 ms
71,896 KB
testcase_23 AC 95 ms
71,820 KB
testcase_24 AC 3,914 ms
283,568 KB
testcase_25 MLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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
        # bfs
        d = deque([i])
        while d:
            x = d.popleft()
            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