結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
67oYG9nh2YMmIci
|
| 提出日時 | 2021-06-12 16:52:25 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 828 bytes |
| 記録 | |
| コンパイル時間 | 640 ms |
| コンパイル使用メモリ | 20,568 KB |
| 実行使用メモリ | 29,400 KB |
| 最終ジャッジ日時 | 2026-05-20 07:02:35 |
| 合計ジャッジ時間 | 16,584 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 TLE * 1 -- * 5 |
ソースコード
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)
67oYG9nh2YMmIci