結果

問題 No.2855 Move on Grid
ユーザー tassei903tassei903
提出日時 2024-08-25 13:55:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 859 ms / 3,000 ms
コード長 1,370 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,296 KB
実行使用メモリ 156,584 KB
最終ジャッジ日時 2024-08-25 13:55:31
合計ジャッジ時間 23,382 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
79,500 KB
testcase_01 AC 284 ms
81,460 KB
testcase_02 AC 232 ms
81,320 KB
testcase_03 AC 170 ms
78,004 KB
testcase_04 AC 161 ms
77,836 KB
testcase_05 AC 233 ms
79,260 KB
testcase_06 AC 228 ms
79,708 KB
testcase_07 AC 113 ms
77,232 KB
testcase_08 AC 202 ms
78,396 KB
testcase_09 AC 158 ms
77,696 KB
testcase_10 AC 528 ms
110,288 KB
testcase_11 AC 559 ms
110,424 KB
testcase_12 AC 578 ms
109,992 KB
testcase_13 AC 441 ms
109,880 KB
testcase_14 AC 550 ms
110,180 KB
testcase_15 AC 591 ms
110,628 KB
testcase_16 AC 587 ms
110,136 KB
testcase_17 AC 456 ms
110,148 KB
testcase_18 AC 595 ms
109,988 KB
testcase_19 AC 556 ms
110,460 KB
testcase_20 AC 621 ms
108,600 KB
testcase_21 AC 674 ms
115,352 KB
testcase_22 AC 656 ms
108,580 KB
testcase_23 AC 620 ms
108,364 KB
testcase_24 AC 651 ms
108,964 KB
testcase_25 AC 666 ms
129,204 KB
testcase_26 AC 623 ms
108,268 KB
testcase_27 AC 755 ms
113,468 KB
testcase_28 AC 620 ms
108,428 KB
testcase_29 AC 629 ms
108,940 KB
testcase_30 AC 668 ms
123,984 KB
testcase_31 AC 764 ms
132,508 KB
testcase_32 AC 686 ms
139,408 KB
testcase_33 AC 855 ms
145,996 KB
testcase_34 AC 785 ms
135,788 KB
testcase_35 AC 859 ms
156,584 KB
testcase_36 AC 683 ms
156,460 KB
testcase_37 AC 808 ms
133,752 KB
testcase_38 AC 736 ms
145,708 KB
testcase_39 AC 709 ms
125,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
n,m,k = na()
a = [na() for i in range(n)]

ok = 0
ng = 10 ** 9 + 1
from collections import deque
while (ng - ok) > 1:
    mid = (ok + ng) // 2
    dp = [[10 ** 18] * m for i in range(n)]
    if a[0][0] >= mid:
        dq = deque([(0, 0, 0)])
        dp[0][0] = 0
    else:
        dq = deque([(1, 0, 0)])
        dp[0][0] = 1
    while dq:
        c, x, y = dq.popleft()
        if dp[x][y] < c:
            continue
        for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            nx, ny = x + dx, y + dy
            if 0 <= nx < n and 0 <= ny < m:
                if a[nx][ny] < mid:
                    nc = c + 1
                    if dp[nx][ny] > nc:
                        dp[nx][ny] = nc
                        dq.append((nc, nx, ny))
                else:
                    nc = c
                    if dp[nx][ny] > nc:
                        dp[nx][ny] = nc
                        dq.appendleft((nc, nx, ny))


    if dp[n - 1][m - 1] <= k:
        ok = mid
    else:
        ng = mid

print(ok)
0