結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2019-08-12 11:33:04 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 664 bytes |
コンパイル時間 | 571 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 98,432 KB |
最終ジャッジ日時 | 2024-11-25 15:05:08 |
合計ジャッジ時間 | 49,372 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 TLE * 6 |
ソースコード
from collections import deque 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)