結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
prin_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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
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)
prin_kemkem