結果

問題 No.2855 Move on Grid
ユーザー prin_kemkemprin_kemkem
提出日時 2024-08-25 14:32:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,022 ms / 3,000 ms
コード長 1,763 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,148 KB
実行使用メモリ 186,716 KB
最終ジャッジ日時 2024-08-25 14:33:20
合計ジャッジ時間 29,329 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
87,256 KB
testcase_01 AC 422 ms
93,544 KB
testcase_02 AC 166 ms
88,048 KB
testcase_03 AC 230 ms
83,936 KB
testcase_04 AC 207 ms
83,496 KB
testcase_05 AC 285 ms
86,520 KB
testcase_06 AC 296 ms
88,912 KB
testcase_07 AC 157 ms
82,196 KB
testcase_08 AC 277 ms
85,552 KB
testcase_09 AC 200 ms
83,060 KB
testcase_10 AC 736 ms
155,244 KB
testcase_11 AC 674 ms
154,844 KB
testcase_12 AC 956 ms
166,728 KB
testcase_13 AC 719 ms
154,740 KB
testcase_14 AC 674 ms
155,456 KB
testcase_15 AC 677 ms
154,936 KB
testcase_16 AC 681 ms
154,840 KB
testcase_17 AC 903 ms
162,632 KB
testcase_18 AC 703 ms
155,060 KB
testcase_19 AC 712 ms
154,824 KB
testcase_20 AC 863 ms
136,448 KB
testcase_21 AC 926 ms
143,620 KB
testcase_22 AC 862 ms
137,720 KB
testcase_23 AC 840 ms
138,360 KB
testcase_24 AC 829 ms
134,600 KB
testcase_25 AC 938 ms
155,884 KB
testcase_26 AC 839 ms
138,476 KB
testcase_27 AC 851 ms
141,016 KB
testcase_28 AC 833 ms
135,000 KB
testcase_29 AC 869 ms
136,884 KB
testcase_30 AC 1,002 ms
148,060 KB
testcase_31 AC 890 ms
156,632 KB
testcase_32 AC 843 ms
162,516 KB
testcase_33 AC 619 ms
142,960 KB
testcase_34 AC 967 ms
164,268 KB
testcase_35 AC 1,007 ms
186,716 KB
testcase_36 AC 294 ms
109,592 KB
testcase_37 AC 906 ms
163,664 KB
testcase_38 AC 951 ms
177,264 KB
testcase_39 AC 1,022 ms
158,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque, Counter
# from functools import cache
# import copy
from itertools import combinations, permutations, product, accumulate, groupby, chain
# from more_itertools import distinct_permutations
from heapq import heapify, heappop, heappush
import math
import bisect
from pprint import pprint
from random import randint, shuffle, randrange
import sys
# sys.setrecursionlimit(200000)
input = lambda: sys.stdin.readline().rstrip('\n')
inf = float('inf')
mod1 = 10**9+7
mod2 = 998244353
def ceil_div(x, y): return -(-x//y)

#################################################   

def f(i, j):
    return i*M + j

D = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def judge(x):
    board = [inf]*(N*M)
    board[0] = A[0][0] < x
    dq = deque([(board[0], 0, 0)])
    while dq:
        k, i, j = dq.pop()
        if k > board[f(i, j)]: continue
        for di, dj in D:
            ni = i+di; nj = j+dj
            if 0 <= ni < N and 0 <= nj < M:
                if A[ni][nj] < x:
                    nk = k+1
                    if nk < board[f(ni, nj)] and nk <= K:
                        board[f(ni, nj)] = nk
                        if ni == N-1 and nj == M-1: return True
                        dq.appendleft((nk, ni, nj))
                else:
                    nk = k
                    if nk < board[f(ni, nj)]:
                        board[f(ni, nj)] = nk
                        if ni == N-1 and nj == M-1: return True
                        dq.append((nk, ni, nj))
    return False

N, M, K = map(int, input().split())
K = min(K, N+M)
A = [list(map(int, input().split())) for _ in range(N)]
ok, ng = 1, 10**9+1
while(abs(ok-ng)>1):
    mid = (ok+ng)//2
    if judge(mid):
        ok = mid
    else:
        ng = mid
print(ok)
0