結果

問題 No.2328 Build Walls
ユーザー sepa38sepa38
提出日時 2023-04-13 11:35:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 629 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 82,972 KB
実行使用メモリ 150,160 KB
最終ジャッジ日時 2024-04-17 16:23:34
合計ジャッジ時間 19,675 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
61,308 KB
testcase_01 AC 30 ms
52,224 KB
testcase_02 AC 32 ms
52,224 KB
testcase_03 AC 34 ms
52,736 KB
testcase_04 AC 31 ms
52,736 KB
testcase_05 AC 29 ms
52,352 KB
testcase_06 AC 32 ms
52,608 KB
testcase_07 AC 31 ms
52,736 KB
testcase_08 AC 31 ms
52,608 KB
testcase_09 AC 32 ms
52,352 KB
testcase_10 AC 30 ms
52,224 KB
testcase_11 AC 30 ms
52,224 KB
testcase_12 AC 29 ms
52,480 KB
testcase_13 AC 119 ms
82,304 KB
testcase_14 AC 917 ms
97,744 KB
testcase_15 AC 479 ms
83,180 KB
testcase_16 AC 130 ms
77,568 KB
testcase_17 AC 317 ms
80,972 KB
testcase_18 AC 93 ms
76,768 KB
testcase_19 AC 42 ms
67,072 KB
testcase_20 AC 115 ms
77,184 KB
testcase_21 AC 62 ms
76,928 KB
testcase_22 AC 1,603 ms
131,636 KB
testcase_23 AC 1,662 ms
104,496 KB
testcase_24 AC 1,368 ms
98,716 KB
testcase_25 AC 1,622 ms
103,552 KB
testcase_26 AC 825 ms
91,256 KB
testcase_27 AC 1,179 ms
95,644 KB
testcase_28 AC 79 ms
80,256 KB
testcase_29 AC 1,664 ms
104,748 KB
testcase_30 AC 150 ms
88,188 KB
testcase_31 AC 132 ms
87,880 KB
testcase_32 AC 1,178 ms
95,336 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h-2)]
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, [a[i][0], i, 0])
while hq:
  d, x, y = 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, [d+a[p][q], p, q])
print(-1)
0