結果

問題 No.697 池の数はいくつか
ユーザー ああいいああいい
提出日時 2022-03-07 19:51:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 576 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 86,752 KB
実行使用メモリ 474,960 KB
最終ジャッジ日時 2023-09-29 21:03:24
合計ジャッジ時間 14,462 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,120 KB
testcase_01 AC 64 ms
70,884 KB
testcase_02 AC 65 ms
71,220 KB
testcase_03 AC 61 ms
71,032 KB
testcase_04 AC 64 ms
71,116 KB
testcase_05 AC 62 ms
71,200 KB
testcase_06 AC 66 ms
71,120 KB
testcase_07 AC 64 ms
70,992 KB
testcase_08 AC 64 ms
71,212 KB
testcase_09 AC 61 ms
71,148 KB
testcase_10 WA -
testcase_11 AC 62 ms
71,340 KB
testcase_12 AC 66 ms
71,344 KB
testcase_13 AC 66 ms
71,320 KB
testcase_14 AC 61 ms
71,264 KB
testcase_15 AC 61 ms
71,156 KB
testcase_16 AC 63 ms
71,016 KB
testcase_17 AC 61 ms
71,276 KB
testcase_18 AC 63 ms
71,372 KB
testcase_19 AC 62 ms
71,364 KB
testcase_20 AC 67 ms
71,008 KB
testcase_21 AC 63 ms
71,376 KB
testcase_22 AC 65 ms
71,168 KB
testcase_23 AC 65 ms
70,992 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
stack = []
for h in range(H):
    for w in range(W):
        if A[h][w] == 1:
            count += 1
            stack.append((h,w))
            A[h][w] = 0
            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]:
                            A[h+i][w+j] = 0
                            stack.append((h+i,w+j))
print(count)
0