結果
問題 |
No.2855 Move on Grid
|
ユーザー |
|
提出日時 | 2023-10-26 10:20:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,198 ms / 3,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 268,068 KB |
最終ジャッジ日時 | 2024-08-25 13:01:59 |
合計ジャッジ時間 | 31,098 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)] 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[y][x] != -1: continue cost[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[ny][nx] == -1: if a[ny][nx] < mid: que.append((nx, ny, c + 1)) else: que.appendleft((nx, ny, c)) if cost[n - 1][m - 1] <= k: l = mid else: r = mid print(l)