結果

問題 No.34 砂漠の行商人
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-24 04:51:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 923 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 508,620 KB
最終ジャッジ日時 2023-10-21 15:35:32
合計ジャッジ時間 28,960 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
59,020 KB
testcase_01 AC 51 ms
62,164 KB
testcase_02 AC 69 ms
73,880 KB
testcase_03 AC 46 ms
63,116 KB
testcase_04 AC 152 ms
107,124 KB
testcase_05 AC 159 ms
117,544 KB
testcase_06 AC 87 ms
89,652 KB
testcase_07 AC 203 ms
138,800 KB
testcase_08 AC 251 ms
162,816 KB
testcase_09 AC 1,904 ms
289,764 KB
testcase_10 AC 285 ms
199,324 KB
testcase_11 RE -
testcase_12 AC 128 ms
108,484 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 111 ms
110,948 KB
testcase_16 AC 311 ms
129,640 KB
testcase_17 AC 124 ms
134,980 KB
testcase_18 AC 93 ms
82,976 KB
testcase_19 AC 1,474 ms
321,060 KB
testcase_20 AC 2,698 ms
426,028 KB
testcase_21 AC 177 ms
180,440 KB
testcase_22 AC 184 ms
176,464 KB
testcase_23 AC 118 ms
123,516 KB
testcase_24 AC 3,838 ms
439,120 KB
testcase_25 AC 233 ms
146,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 100000
U = 10009
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]

N, V, sy, sx, gy, gx = map(int, input().split())
L = tuple(tuple(map(int, input().split())) for _ in range(N))
sy -= 1
sx -= 1
gx -= 1
gy -= 1

dist = [[[inf] * 1501 for _ in range(N)] for _ in range(N)]
dist[sx][sy][0] = 0
que = deque([(sx, sy, 0)])
while que:
    x, y, now = que.popleft()
    if (x, y) == (gx, gy):
        break
    d = dist[x][y][now]
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < N and 0 <= ny < N:
            nxt = now + L[nx][ny]
            if nxt < V and dist[nx][ny][nxt] > d + 1:
                dist[nx][ny][nxt] = d + 1
                que.append((nx, ny, nxt))

ans = min(dist[gx][gy])
if ans >= inf:
    ans = -1
print(ans)
0