結果

問題 No.2855 Move on Grid
ユーザー miya145592miya145592
提出日時 2024-08-25 14:16:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 713 ms / 3,000 ms
コード長 1,069 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 91,436 KB
最終ジャッジ日時 2024-08-25 14:16:52
合計ジャッジ時間 16,956 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 218 ms
78,900 KB
testcase_01 AC 291 ms
79,408 KB
testcase_02 AC 231 ms
79,016 KB
testcase_03 AC 210 ms
78,496 KB
testcase_04 AC 173 ms
78,240 KB
testcase_05 AC 215 ms
78,600 KB
testcase_06 AC 248 ms
79,580 KB
testcase_07 AC 122 ms
77,832 KB
testcase_08 AC 222 ms
78,464 KB
testcase_09 AC 180 ms
78,252 KB
testcase_10 AC 58 ms
76,400 KB
testcase_11 AC 58 ms
76,224 KB
testcase_12 AC 56 ms
76,416 KB
testcase_13 AC 60 ms
76,184 KB
testcase_14 AC 58 ms
76,204 KB
testcase_15 AC 58 ms
76,172 KB
testcase_16 AC 56 ms
76,248 KB
testcase_17 AC 56 ms
75,908 KB
testcase_18 AC 56 ms
75,940 KB
testcase_19 AC 56 ms
76,276 KB
testcase_20 AC 688 ms
89,216 KB
testcase_21 AC 543 ms
89,704 KB
testcase_22 AC 683 ms
89,240 KB
testcase_23 AC 657 ms
88,912 KB
testcase_24 AC 701 ms
89,156 KB
testcase_25 AC 547 ms
88,884 KB
testcase_26 AC 571 ms
89,004 KB
testcase_27 AC 677 ms
89,504 KB
testcase_28 AC 581 ms
89,384 KB
testcase_29 AC 616 ms
88,524 KB
testcase_30 AC 713 ms
89,488 KB
testcase_31 AC 682 ms
89,912 KB
testcase_32 AC 705 ms
90,928 KB
testcase_33 AC 666 ms
90,724 KB
testcase_34 AC 561 ms
89,764 KB
testcase_35 AC 680 ms
91,436 KB
testcase_36 AC 573 ms
91,240 KB
testcase_37 AC 559 ms
89,736 KB
testcase_38 AC 577 ms
90,192 KB
testcase_39 AC 535 ms
89,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
if N+M-1<=K:
    print(10**9)
    exit()
B = [[0 for _ in range(M)] for _ in range(N)]
l = 0
r = 10**9+1
while r-l>1:
    mid = (l+r)//2
    for i in range(N):
        for j in range(M):
            B[i][j] = 1 if A[i][j]<mid else 0
    deq = deque()
    deq.append((0, 0))
    INF = 10**9
    dist = [[INF for _ in range(M)] for _ in range(N)]
    dist[0][0] = B[0][0]
    dir = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    while deq:
        i, j = deq.popleft()
        for di, dj in dir:
            ni = i+di
            nj = j+dj
            if 0<=ni<N and 0<=nj<M:
                if dist[ni][nj]>dist[i][j]+B[ni][nj]:
                    dist[ni][nj] = dist[i][j]+B[ni][nj]
                    if B[ni][nj]==0:
                        deq.appendleft((ni, nj))
                    else:
                        deq.append((ni, nj))
    if dist[N-1][M-1]<=K:
        l = mid
    else:
        r = mid
print(l)
0