結果
問題 |
No.2855 Move on Grid
|
ユーザー |
![]() |
提出日時 | 2024-09-23 12:46:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 882 ms / 3,000 ms |
コード長 | 1,105 bytes |
コンパイル時間 | 5,322 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 122,072 KB |
最終ジャッジ日時 | 2024-09-23 12:49:09 |
合計ジャッジ時間 | 36,124 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
import sys input = sys.stdin.readline N, M, K = map(int, input().split()) A = [] for i in range(N): A.append(list(map(int, input().split()))) from collections import * def check(mid): inf = 10 ** 18 D = [[inf] * M for _ in range(N)] Q = deque() D[0][0] = int(A[0][0] < mid) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] Q.append((0, 0)) while Q: px, py = Q.popleft() for k in range(4): x, y = px + dx[k], py + dy[k] if x < 0 or x > N - 1 or y < 0 or y > M - 1: continue if D[x][y] != inf and D[x][y] <= D[px][py] + int(A[x][y] < mid): continue D[x][y] = D[px][py] + int(A[x][y] < mid) if A[x][y] < mid: Q.append((x, y)) else: Q.appendleft((x, y)) return D[N-1][M-1] def BinarySearch(yes = 10 ** 18, no = -1): while abs(yes - no) != 1: mid = (yes + no)//2 if check(mid) <= K: yes = mid else: no = mid return yes print(BinarySearch(1, 10**9+1))