結果

問題 No.697 池の数はいくつか
ユーザー lloyz
提出日時 2022-07-14 20:15:25
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 401 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 320,848 KB
最終ジャッジ日時 2026-05-08 14:58:20
合計ジャッジ時間 11,262 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque

Directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]

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

visited = [[False for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if A[i][j] == 0:
            visited[i][j] = True

ans = 0
for i in range(h):
    for j in range(w):
        if not visited[i][j]:
            ans += 1
            Que = deque([(i, j)])
            visited[i][j] = True
            while Que:
                ci, cj = Que.popleft()
                for di, dj in Directions:
                    ni, nj = ci + di, cj + dj
                    if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
                        visited[ni][nj] = True
                        Que.append((ni, nj))
print(ans)
0