結果

問題 No.697 池の数はいくつか
ユーザー ああいい
提出日時 2022-03-07 19:48:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 533,548 KB
最終ジャッジ日時 2024-07-22 14:54:00
合計ジャッジ時間 18,363 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 10 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

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