結果

問題 No.34 砂漠の行商人
ユーザー zimphazimpha
提出日時 2017-12-12 12:26:59
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 851 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 288,716 KB
最終ジャッジ日時 2023-08-20 22:17:58
合計ジャッジ時間 15,818 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
85,188 KB
testcase_01 AC 181 ms
82,500 KB
testcase_02 AC 205 ms
83,500 KB
testcase_03 AC 163 ms
80,732 KB
testcase_04 AC 348 ms
89,656 KB
testcase_05 AC 354 ms
89,860 KB
testcase_06 AC 195 ms
83,088 KB
testcase_07 AC 450 ms
93,688 KB
testcase_08 AC 570 ms
99,976 KB
testcase_09 AC 175 ms
80,800 KB
testcase_10 AC 174 ms
80,820 KB
testcase_11 AC 178 ms
80,720 KB
testcase_12 AC 307 ms
87,836 KB
testcase_13 AC 177 ms
80,824 KB
testcase_14 AC 177 ms
80,792 KB
testcase_15 AC 171 ms
80,932 KB
testcase_16 AC 174 ms
80,736 KB
testcase_17 AC 168 ms
80,968 KB
testcase_18 AC 172 ms
80,900 KB
testcase_19 AC 3,425 ms
284,340 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import Queue

def solve():
  n, v, sy, sx, gy, gx = list(map(int, input().split()))
  if v > (abs(sx - gx) + abs(sy - gy)) * 9:
    return abs(sx - gx) + abs(sy - gy)
  gx, gy = gx - 1, gy - 1
  g = [list(map(int, input().split())) for i in range(n)]
  dis = [[[-1] * (v + 1) for j in range(n)] for i in range(n)]
  dis[sx - 1][sy - 1][v] = 0;
  queue = Queue()
  queue.put((sx - 1, sy - 1, v))
  dx = [0, 0, 1, -1]
  dy = [1, -1, 0, 0]
  while not queue.empty():
    u = queue.get()
    for i in range(4):
      x, y = u[0] + dx[i], u[1] + dy[i]
      if x < 0 or x >= n or y < 0 or y >= n:
        continue
      z = u[2] - g[x][y]
      if z > 0 and dis[x][y][z] == -1:
        dis[x][y][z] = dis[u[0]][u[1]][u[2]] + 1
        if x == gx and y == gy:
          return dis[x][y][z]
        queue.put((x, y, z))
  return -1

print(solve())
0