結果

問題 No.697 池の数はいくつか
ユーザー ああいい
提出日時 2021-12-24 13:01:24
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 664 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 56 ms
コンパイル使用メモリ 15,232 KB
実行使用メモリ 530,772 KB
最終ジャッジ日時 2026-09-29 23:06:36
合計ジャッジ時間 18,692 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 MLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

memo = [[False] * W for _ in range(H)]
ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] and memo[h][w] == False:
            ans += 1
            memo[h][w] = True
            q = []
            q.append((h,w))
            while len(q):
                x,y = q.pop()
                for i,j in [[-1,0],[1,0],[0,1],[0,-1]]:
                    if 0 <= x + i < H and 0 <= y + j < W:
                        if A[x+i][y+j] and memo[x+i][y+j] == False:
                            memo[x+i][y+j] = True
                            q.append((x+i,y+j))
print(ans)
0