結果
問題 | No.697 池の数はいくつか |
ユーザー |
|
提出日時 | 2025-01-06 23:17:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 838 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 817,624 KB |
最終ジャッジ日時 | 2025-01-06 23:18:02 |
合計ジャッジ時間 | 52,523 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 MLE * 2 |
other | AC * 25 TLE * 3 MLE * 4 |
ソースコード
from collections import deque h, w = map(int, input().split()) grid = [list(input().split()) for _ in range(h)] sensor = set() q = deque() visited = set() for j in range(h): for i in range(w): if grid[j][i] == '1': sensor.add((i, j)) count = 0 while sensor: q.append(sensor.pop()) while q: x, y = q.popleft() if (x, y) in sensor: sensor.remove((x, y)) for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]: nx, ny = x + dx, y + dy if nx < 0 or w <= nx or ny < 0 or h <= ny: continue if grid[ny][nx] == '0': continue if (nx, ny) not in visited and grid[ny][nx] == '1': visited.add((nx, ny)) q.append((nx, ny)) count += 1 print(count)