結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-09-02 00:21:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,051 ms / 3,000 ms |
| コード長 | 865 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 82,008 KB |
| 実行使用メモリ | 151,508 KB |
| 最終ジャッジ日時 | 2024-09-02 00:21:37 |
| 合計ジャッジ時間 | 29,687 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
import sys
input = sys.stdin.readline
from collections import deque
N,M,K=map(int,input().split())
MAP=[list(map(int,input().split())) for i in range(N)]
OK=0
NG=10**9+1
while NG>OK+1:
mid=(OK+NG)//2
DP=[[1<<63]*M for i in range(N)]
if MAP[0][0]<mid:
DP[0][0]=1
else:
DP[0][0]=0
Q=deque()
Q.append((0,0))
while Q:
x,y=Q.popleft()
for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
if 0<=z<N and 0<=w<M:
if MAP[z][w]<mid:
if DP[z][w]>DP[x][y]+1:
DP[z][w]=DP[x][y]+1
Q.append((z,w))
else:
if DP[z][w]>DP[x][y]:
DP[z][w]=DP[x][y]
Q.appendleft((z,w))
if DP[-1][-1]<=K:
OK=mid
else:
NG=mid
print(OK)
titia