結果

問題 No.697 池の数はいくつか
ユーザー roaris
提出日時 2019-08-12 11:34:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 702 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 98,304 KB
最終ジャッジ日時 2024-11-25 15:07:30
合計ジャッジ時間 49,051 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def bfs(sx, sy):
    S[sx][sy] = 0
    queue = deque([])
    queue.append((sx, sy))
    
    while len(queue) > 0:
        cx, cy = queue.popleft()
        
        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            nx, ny = cx + dx, cy + dy
            if 0 <= nx < H and 0 <= ny < W:
                if S[nx][ny] == 1:
                    S[nx][ny] = 0
                    queue.append((nx, ny))
    
H, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == 1:
            bfs(i, j)
            ans += 1

print(ans)
0