結果

問題 No.2855 Move on Grid
ユーザー ryuusagiryuusagi
提出日時 2024-08-25 14:30:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 638 ms / 3,000 ms
コード長 911 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 115,036 KB
最終ジャッジ日時 2024-08-25 14:30:20
合計ジャッジ時間 17,695 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
78,820 KB
testcase_01 AC 213 ms
81,012 KB
testcase_02 AC 172 ms
79,392 KB
testcase_03 AC 152 ms
78,140 KB
testcase_04 AC 131 ms
78,064 KB
testcase_05 AC 193 ms
79,100 KB
testcase_06 AC 171 ms
79,428 KB
testcase_07 AC 103 ms
76,980 KB
testcase_08 AC 154 ms
78,472 KB
testcase_09 AC 126 ms
77,528 KB
testcase_10 AC 387 ms
114,808 KB
testcase_11 AC 348 ms
114,800 KB
testcase_12 AC 388 ms
115,020 KB
testcase_13 AC 348 ms
114,936 KB
testcase_14 AC 365 ms
115,012 KB
testcase_15 AC 365 ms
115,036 KB
testcase_16 AC 360 ms
114,968 KB
testcase_17 AC 416 ms
114,748 KB
testcase_18 AC 352 ms
114,048 KB
testcase_19 AC 362 ms
115,020 KB
testcase_20 AC 463 ms
106,088 KB
testcase_21 AC 570 ms
105,972 KB
testcase_22 AC 447 ms
105,200 KB
testcase_23 AC 463 ms
105,592 KB
testcase_24 AC 567 ms
106,148 KB
testcase_25 AC 638 ms
108,504 KB
testcase_26 AC 433 ms
105,736 KB
testcase_27 AC 547 ms
105,108 KB
testcase_28 AC 447 ms
104,620 KB
testcase_29 AC 437 ms
105,348 KB
testcase_30 AC 585 ms
108,248 KB
testcase_31 AC 525 ms
108,108 KB
testcase_32 AC 446 ms
109,984 KB
testcase_33 AC 478 ms
110,788 KB
testcase_34 AC 473 ms
110,240 KB
testcase_35 AC 605 ms
113,400 KB
testcase_36 AC 543 ms
111,820 KB
testcase_37 AC 475 ms
109,304 KB
testcase_38 AC 526 ms
109,436 KB
testcase_39 AC 561 ms
108,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import*

n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

ng = 10 ** 9 + 1
ok = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    # begin mid が ok かどうか判定する為の前処理
    dp = [[-1] * m for _ in range(n)]
    dp[0][0] = int(a[0][0] < mid)
    q = deque([(0, 0)])
    while q:
        i, j = q.popleft()
        for x, y in [(i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j)]:
            if 0 <= x < n and 0 <= y < m and dp[x][y] == -1:
                if a[x][y] < mid:
                    dp[x][y] = dp[i][j] + 1
                    q.append((x, y))
                else:
                    dp[x][y] = dp[i][j]
                    q.appendleft((x, y))
    # end mid が ok かどうか判定する為の前処理
    if dp[-1][-1] <= k: # mid が ok の場合の条件
        ok = mid
    else:
        ng = mid
print(ok)
0