結果

問題 No.697 池の数はいくつか
ユーザー dice4084
提出日時 2022-12-27 22:42:18
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 800 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 269 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 850,388 KB
最終ジャッジ日時 2026-05-16 12:31:27
合計ジャッジ時間 19,134 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 1 MLE * 2 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
from collections import deque
from itertools import product

h, w = map(int, input().split())
a = [[0]*(w+2)] + [[0] + list(map(int, input().split())) + [0] for _ in range(h)] + [[0]*(w+2)]
arrived = [[False]*(w+2) for _ in range(h+2)]

dyx = ((1, 0), (-1, 0), (0, 1), (0, -1))
ans = 0
for i, j in product(range(1, h+1), range(1, w+1)):
    if a[i][j] == 0:
        continue
    if arrived[i][j]:
        continue

    ans += 1
    q = deque([(i, j)])
    while q:
        y, x = q.popleft()
        arrived[y][x] = True
        for dy, dx in dyx:
            new_y, new_x = (y+dy, x+dx)
            if a[new_y][new_x] == 0:
                continue
            if arrived[new_y][new_x]:
                continue
            q.append((new_y, new_x))

print(ans)
0