結果

問題 No.697 池の数はいくつか
ユーザー kawacchu
提出日時 2019-09-16 19:43:41
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 691 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 410 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 246,144 KB
最終ジャッジ日時 2026-05-20 05:26:16
合計ジャッジ時間 9,550 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
from collections import deque
H,W = map(int,input().split())
A = [list(map(int,input().split())) for y in range(H)]
ans = 0
dxy = [(-1,0), (0,-1), (0,1), (1,0)]
for y in range(H) :
    for x in range(W) :
        if A[y][x] != 1 :
            continue
        ans += 1
        A[y][x] = 0
        q = deque([(y, x)])
        while q :
            y, x = q.popleft()
            for dy,dx in dxy :
                ny,nx = y+dy, x+dx
                if ny<0 or ny>=H or nx<0 or nx>=W :
                    continue
                if A[ny][nx] != 1 :
                    continue
                q.append((ny, nx))
                A[ny][nx] = 0
print(ans)
0