結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2021-06-12 16:52:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 828 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 168,832 KB |
最終ジャッジ日時 | 2024-11-25 17:02:49 |
合計ジャッジ時間 | 51,326 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 TLE * 6 |
ソースコード
from collections import deque H, W = map(int, input().split()) pond = [] for i in range(H): a = [int(i) for i in input().split()] pond.append(a) ans = 0 q = deque() toward = [[0, 1], [0, -1], [1, 0], [-1, 0]] visited = [([False] * W) for i in range(H)] def search(): while len(q) > 0: x, y = q.popleft() visited[x][y] = True for k in range(4): dx, dy = x + toward[k][0], y + toward[k][1] if (0 <= dx < H) and (0 <= dy < W): if (pond[dx][dy] == 1) and (visited[dx][dy] == False): visited[dx][dy] = True q.append([dx, dy]) for i in range(H): for j in range(W): if (pond[i][j] == 1) and (visited[i][j] == False): q.append([i, j]) search() ans += 1 print(ans)