結果

問題 No.2855 Move on Grid
ユーザー sepa38sepa38
提出日時 2023-10-26 11:20:29
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,331 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 152,104 KB
最終ジャッジ日時 2024-08-25 13:03:12
合計ジャッジ時間 49,100 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,086 ms
104,660 KB
testcase_01 AC 1,195 ms
101,184 KB
testcase_02 AC 303 ms
83,672 KB
testcase_03 AC 900 ms
91,564 KB
testcase_04 AC 752 ms
87,908 KB
testcase_05 AC 1,064 ms
97,128 KB
testcase_06 AC 860 ms
94,460 KB
testcase_07 AC 267 ms
80,520 KB
testcase_08 AC 1,028 ms
95,264 KB
testcase_09 AC 417 ms
83,004 KB
testcase_10 AC 1,076 ms
115,876 KB
testcase_11 AC 1,034 ms
117,672 KB
testcase_12 AC 1,046 ms
110,768 KB
testcase_13 AC 1,039 ms
113,496 KB
testcase_14 AC 1,002 ms
113,780 KB
testcase_15 AC 1,026 ms
117,400 KB
testcase_16 AC 1,032 ms
113,164 KB
testcase_17 AC 1,013 ms
115,396 KB
testcase_18 AC 1,029 ms
112,548 KB
testcase_19 AC 1,050 ms
113,192 KB
testcase_20 AC 2,248 ms
143,552 KB
testcase_21 AC 2,298 ms
145,864 KB
testcase_22 AC 2,217 ms
146,564 KB
testcase_23 AC 2,240 ms
144,380 KB
testcase_24 AC 2,261 ms
152,104 KB
testcase_25 AC 2,073 ms
149,296 KB
testcase_26 AC 2,231 ms
145,276 KB
testcase_27 AC 2,194 ms
143,652 KB
testcase_28 AC 2,202 ms
143,148 KB
testcase_29 AC 2,280 ms
143,784 KB
testcase_30 AC 1,899 ms
145,860 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
inf = 10 ** 9 + 1
l, r = 0, inf
while r - l > 1:
  piv = (l + r) // 2
  dist = [inf] * (n * m)
  dist[0] = a[0][0] < piv
  d = deque([dist[0]*n*m])
  while d:
    c, u = divmod(d.popleft(), n*m)
    if u == n * m - 1:
    	break
    i, j = u // m, u % m
    if 0 < i:
      dis = c + (a[i-1][j] < piv)
      if dis < dist[u-m] and dis <= k:
        dist[u-m] = dis
        if a[i-1][j] < piv:
          d.append(dis*n*m+u-m)
        else:
          d.appendleft(dis*n*m+u-m)
    if i < n - 1:
      dis = c + (a[i+1][j] < piv)
      if dis < dist[u+m] and dis <= k:
        dist[u+m] = dis
        if a[i+1][j] < piv:
          d.append(dis*n*m+u+m)
        else:
          d.appendleft(dis*n*m+u+m)
    if 0 < j:
      dis = c + (a[i][j-1] < piv)
      if dis < dist[u-1] and dis <= k:
        dist[u-1] = dis
        if a[i][j-1] < piv:
          d.append(dis*n*m+u-1)
        else:
          d.appendleft(dis*n*m+u-1)
    if j < m - 1:
      dis = c + (a[i][j+1] < piv)
      if dis < dist[u+1] and dis <= k:
        dist[u+1] = dis
        if a[i][j+1] < piv:
          d.append(dis*n*m+u+1)
        else:
          d.appendleft(dis*n*m+u+1)
  if dist[n*m-1] <= k:
    l = piv
  else:
    r = piv
print(l)
0