結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2022-10-05 13:19:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 805 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 82,896 KB
実行使用メモリ 315,540 KB
最終ジャッジ日時 2024-06-10 04:10:43
合計ジャッジ時間 14,113 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,016 KB
testcase_01 AC 37 ms
54,016 KB
testcase_02 AC 38 ms
54,144 KB
testcase_03 AC 37 ms
54,400 KB
testcase_04 AC 37 ms
54,400 KB
testcase_05 AC 37 ms
54,016 KB
testcase_06 AC 37 ms
54,016 KB
testcase_07 AC 37 ms
54,528 KB
testcase_08 AC 36 ms
54,144 KB
testcase_09 AC 36 ms
54,016 KB
testcase_10 AC 39 ms
54,016 KB
testcase_11 AC 36 ms
54,144 KB
testcase_12 AC 37 ms
54,272 KB
testcase_13 AC 37 ms
54,144 KB
testcase_14 AC 36 ms
54,400 KB
testcase_15 AC 37 ms
54,016 KB
testcase_16 AC 39 ms
54,016 KB
testcase_17 AC 40 ms
54,144 KB
testcase_18 AC 38 ms
54,016 KB
testcase_19 AC 38 ms
54,272 KB
testcase_20 AC 36 ms
54,016 KB
testcase_21 AC 38 ms
54,144 KB
testcase_22 AC 42 ms
54,272 KB
testcase_23 AC 41 ms
54,528 KB
testcase_24 AC 208 ms
87,296 KB
testcase_25 AC 211 ms
87,168 KB
testcase_26 AC 207 ms
87,552 KB
testcase_27 AC 211 ms
87,384 KB
testcase_28 AC 203 ms
87,152 KB
testcase_29 MLE -
testcase_30 AC 1,100 ms
173,040 KB
testcase_31 MLE -
testcase_32 AC 1,207 ms
172,912 KB
testcase_33 AC 1,193 ms
173,184 KB
testcase_34 AC 1,193 ms
173,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from array import array
from collections import deque

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