結果

問題 No.697 池の数はいくつか
ユーザー ああいいああいい
提出日時 2022-03-07 19:48:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 534,048 KB
最終ジャッジ日時 2023-09-29 20:59:27
合計ジャッジ時間 19,761 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,432 KB
testcase_01 AC 65 ms
71,176 KB
testcase_02 AC 64 ms
71,424 KB
testcase_03 AC 64 ms
71,164 KB
testcase_04 AC 64 ms
71,316 KB
testcase_05 AC 64 ms
71,364 KB
testcase_06 AC 66 ms
71,432 KB
testcase_07 AC 67 ms
71,284 KB
testcase_08 AC 67 ms
71,324 KB
testcase_09 AC 67 ms
71,392 KB
testcase_10 WA -
testcase_11 AC 67 ms
71,436 KB
testcase_12 AC 66 ms
71,428 KB
testcase_13 AC 66 ms
71,348 KB
testcase_14 AC 66 ms
71,404 KB
testcase_15 AC 66 ms
71,380 KB
testcase_16 AC 63 ms
71,272 KB
testcase_17 AC 66 ms
71,476 KB
testcase_18 AC 65 ms
71,432 KB
testcase_19 AC 67 ms
71,316 KB
testcase_20 AC 68 ms
71,248 KB
testcase_21 AC 63 ms
71,128 KB
testcase_22 AC 65 ms
71,504 KB
testcase_23 AC 66 ms
71,460 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 MLE -
testcase_30 WA -
testcase_31 MLE -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

count = 0
memo = [[0] * W for _ in range(H)]
stack = []
for h in range(H):
    for w in range(W):
        if A[h][w] == 1 and memo[h][w] == 0:
            count += 1
            stack.append((h,w))
            memo[h][w] = 1
            while stack:
                h,w = stack.pop()
                for i,j in [(0,1),(0,-1),(1,0),(-1,0)]:
                    if 0 <= h + i < H and 0 <= w + j < W:
                        if A[h+i][w+j] and not memo[h+i][w+j]:
                            memo[h+i][w+j] = 1
                            stack.append((h+i,w+j))
print(count)
0