結果

問題 No.2328 Build Walls
ユーザー sepa38sepa38
提出日時 2023-04-13 11:45:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,709 ms / 3,000 ms
コード長 793 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 89,108 KB
最終ジャッジ日時 2024-04-17 16:17:54
合計ジャッジ時間 17,351 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,608 KB
testcase_01 AC 44 ms
52,352 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 41 ms
52,608 KB
testcase_04 AC 43 ms
52,864 KB
testcase_05 AC 43 ms
52,608 KB
testcase_06 AC 41 ms
52,352 KB
testcase_07 AC 43 ms
52,992 KB
testcase_08 AC 44 ms
52,864 KB
testcase_09 AC 41 ms
52,992 KB
testcase_10 AC 41 ms
52,352 KB
testcase_11 AC 39 ms
52,480 KB
testcase_12 AC 41 ms
52,352 KB
testcase_13 AC 163 ms
82,712 KB
testcase_14 AC 586 ms
80,700 KB
testcase_15 AC 380 ms
80,644 KB
testcase_16 AC 164 ms
77,972 KB
testcase_17 AC 292 ms
80,640 KB
testcase_18 AC 123 ms
77,216 KB
testcase_19 AC 58 ms
66,944 KB
testcase_20 AC 144 ms
77,824 KB
testcase_21 AC 94 ms
76,928 KB
testcase_22 AC 847 ms
82,032 KB
testcase_23 AC 1,041 ms
89,108 KB
testcase_24 AC 912 ms
88,116 KB
testcase_25 AC 1,402 ms
88,640 KB
testcase_26 AC 860 ms
88,192 KB
testcase_27 AC 1,116 ms
88,784 KB
testcase_28 AC 111 ms
80,256 KB
testcase_29 AC 1,056 ms
88,672 KB
testcase_30 AC 195 ms
88,320 KB
testcase_31 AC 180 ms
88,320 KB
testcase_32 AC 856 ms
88,164 KB
testcase_33 AC 1,709 ms
88,356 KB
testcase_34 AC 204 ms
88,064 KB
testcase_35 AC 1,278 ms
88,448 KB
testcase_36 AC 43 ms
52,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h-2)]

def c(d, x, y):
  global h, w
  return d*h*w + x*w + y

def dc(num):
  global h, w
  yield num // (h * w)
  num %= (h * w)
  yield num // w
  yield num % w

inf = 1 << 30
dist = [[inf] * w for _ in range(h-2)]
hq = []
for i in range(h-2):
  if a[i][0] == -1:
    continue
  heapq.heappush(hq, c(a[i][0], i, 0))
while hq:
  d, x, y = dc(heapq.heappop(hq))
  if y == w - 1:
    print(d)
    exit()
  if dist[x][y] <= d:
    continue
  dist[x][y] = d
  for p in range(max(0, x-1), min(h-2, x+2)):
    for q in range(max(0, y-1), min(w, y+2)):
      if a[p][q] == -1:
        continue
      if dist[p][q] <= d + a[p][q]:
        continue
      heapq.heappush(hq, c(d+a[p][q], p, q))
print(-1)
0