結果

問題 No.697 池の数はいくつか
ユーザー ああいい
提出日時 2021-12-24 13:01:24
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
MLE  
実行時間 -
コード長 664 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 319,104 KB
最終ジャッジ日時 2024-11-25 17:06:49
合計ジャッジ時間 55,464 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 MLE * 2
other AC * 26 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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