結果

問題 No.34 砂漠の行商人
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-24 04:50:53
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 922 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 296,192 KB
最終ジャッジ日時 2023-10-21 15:35:03
合計ジャッジ時間 10,315 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
55,524 KB
testcase_01 AC 40 ms
62,044 KB
testcase_02 AC 53 ms
72,504 KB
testcase_03 AC 36 ms
57,572 KB
testcase_04 AC 111 ms
93,600 KB
testcase_05 AC 120 ms
98,952 KB
testcase_06 AC 73 ms
88,444 KB
testcase_07 AC 151 ms
111,768 KB
testcase_08 AC 188 ms
124,520 KB
testcase_09 RE -
testcase_10 AC 200 ms
145,004 KB
testcase_11 RE -
testcase_12 AC 98 ms
93,572 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 96 ms
89,376 KB
testcase_16 AC 238 ms
112,924 KB
testcase_17 AC 91 ms
111,764 KB
testcase_18 AC 78 ms
79,840 KB
testcase_19 AC 1,132 ms
290,120 KB
testcase_20 RE -
testcase_21 AC 112 ms
134,220 KB
testcase_22 AC 120 ms
130,060 KB
testcase_23 AC 87 ms
101,724 KB
testcase_24 RE -
testcase_25 AC 227 ms
118,608 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] * 801 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