結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
学ぶマン
|
| 提出日時 | 2025-09-27 11:57:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,421 bytes |
| コンパイル時間 | 378 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 97,572 KB |
| 最終ジャッジ日時 | 2025-09-27 11:58:00 |
| 合計ジャッジ時間 | 10,439 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 39 |
ソースコード
INF = 10**9
from collections import deque
N, M, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
def chmin(DP,i,v):
if DP[i] > v: DP[i] = v
def check(i, j):
return 0 <= i < N and 0 <= j < M
def solve(x:int): # スコアxを達成可能かの判定関数
initial_cost = 0
if A[0][0] < x:
initial_cost += 1
# 01-BFS
dist = [[INF] * (M) for _ in range(N)]
dist[0][0] = initial_cost
que = deque()
que.append((initial_cost, 0, 0))
while que:
curr_cost, i, j = que.popleft()
for ii, jj in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
ni, nj = i+ii, j+jj
if check(ni, nj):
if A[ni][nj] < x: # Xマスのとき cost 1 追加
if dist[ni][nj] > curr_cost + 1:
dist[ni][nj] = curr_cost + 1
que.appendleft((curr_cost + 1, ni, nj))
else:
# 比較して、小さくなるなら探索
if dist[ni][nj] > curr_cost:
dist[ni][nj] = curr_cost
que.appendleft((curr_cost, ni, nj))
# (N, M) までたどり着いたときのコストは K 以下か?
return dist[-1][-1] <= K
ok = 1
ng = 10**9 + 1
while abs(ok - ng) != 1:
mid = (ok + ng)//2
if solve(mid):
ok = mid
else:
ng = mid
print(ok)
学ぶマン