結果

問題 No.2855 Move on Grid
ユーザー ryota2357
提出日時 2023-10-26 10:22:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 869 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,104 KB
最終ジャッジ日時 2024-08-25 13:02:25
合計ジャッジ時間 22,385 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

l, r = 0, 1000000001

while r - l > 1:
    mid = (l + r) // 2

    que = deque()
    cost = [[-1 for _ in range(m)] for _ in range(n)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que.append((0, 0, 1 if a[0][0] < mid else 0))

    while que:
        x, y, c = que.popleft()

        if cost[y][x] != -1:
            continue

        cost[y][x] = c

        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < m and 0 <= ny < n and cost[ny][nx] == -1:
                if a[ny][nx] < mid:
                    que.append((nx, ny, c + 1))
                else:
                    que.appendleft((nx, ny, c))

    if cost[n - 1][m - 1] <= k:
        l = mid
    else:
        r = mid

print(l)
0