結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-26 10:25:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,060 ms / 3,000 ms |
| コード長 | 921 bytes |
| コンパイル時間 | 303 ms |
| コンパイル使用メモリ | 82,392 KB |
| 実行使用メモリ | 270,748 KB |
| 最終ジャッジ日時 | 2024-08-25 13:03:22 |
| 合計ジャッジ時間 | 26,588 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
from collections import deque
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
l, r = 0, 1000000001
while r - l > 1:
mid = (l + r) // 2
que = deque()
# cost = [[-1 for _ in range(m)] for _ in range(n)]
cost = [-1 for _ in range(m * n)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
que.append((0, 0, 1 if a[0][0] < mid else 0))
while que:
x, y, c = que.popleft()
if cost[m * y + x] != -1:
continue
cost[m * y + x] = c
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < m and 0 <= ny < n and cost[m * ny + nx] == -1:
if a[ny][nx] < mid:
que.append((nx, ny, c + 1))
else:
que.appendleft((nx, ny, c))
if cost[n * m - 1] <= k:
l = mid
else:
r = mid
print(l)