結果
問題 |
No.2855 Move on Grid
|
ユーザー |
![]() |
提出日時 | 2024-08-25 14:06:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 838 ms / 3,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 125,388 KB |
最終ジャッジ日時 | 2024-08-25 14:06:56 |
合計ジャッジ時間 | 24,526 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
N,M,K = map(int,input().split()) A = [list(map(int,input().split())) for i in range(N)] dij = [(0,1),(1,0),(0,-1),(-1,0)] from collections import deque INF = 10**18 def is_ok(k): costs = [[INF]*M for i in range(N)] costs[0][0] = int(A[0][0] < k) q = deque([(0,0)]) while q: i,j = q.popleft() if i == N-1 and j == M-1: return costs[-1][-1] <= K for di,dj in dij: ni,nj = i+di,j+dj if not (0 <= ni < N and 0 <= nj < M): continue cost = int(A[ni][nj] < k) if costs[ni][nj] <= costs[i][j] + cost: continue costs[ni][nj] = costs[i][j] + cost if cost: q.append((ni,nj)) else: q.appendleft((ni,nj)) ok = 0 ng = 10**9+1 while ng - ok > 1: mid = (ok+ng)//2 if is_ok(mid): ok = mid else: ng = mid print(ok)