結果

問題 No.697 池の数はいくつか
ユーザー rlangevin
提出日時 2023-01-26 20:36:42
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 857 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 304 ms
コンパイル使用メモリ 85,136 KB
実行使用メモリ 316,364 KB
最終ジャッジ日時 2026-03-15 07:11:28
合計ジャッジ時間 9,952 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import *

H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(map(int, input().split())))
    
seen = [0] * (H * W)
ans = 0
Q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(H):
    for j in range(W):
        if not G[i][j]:
            continue
        if seen[i*W+j]:
            continue
        seen[i*W+j] = 1
        ans += 1
        Q.append(i*W+j)
        while Q:
            px, py = divmod(Q.popleft(), W)
            for k in range(4):
                x = px + dx[k]
                y = py + dy[k]
                if x < 0 or x > H - 1 or y < 0 or y > W - 1:
                    continue
                if seen[x*W+y]:
                    continue
                if not G[x][y]:
                    continue
                seen[x*W+y] = 1
                Q.append(x * W + y)
print(ans)
0