結果

問題 No.34 砂漠の行商人
ユーザー convexineqconvexineq
提出日時 2021-01-17 03:46:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 913 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 86,668 KB
実行使用メモリ 270,956 KB
最終ジャッジ日時 2023-08-19 10:05:21
合計ジャッジ時間 9,500 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
71,364 KB
testcase_01 AC 105 ms
71,800 KB
testcase_02 AC 121 ms
77,500 KB
testcase_03 AC 101 ms
71,704 KB
testcase_04 AC 146 ms
81,480 KB
testcase_05 AC 155 ms
82,844 KB
testcase_06 AC 126 ms
78,416 KB
testcase_07 AC 183 ms
86,160 KB
testcase_08 AC 210 ms
92,904 KB
testcase_09 AC 390 ms
170,996 KB
testcase_10 AC 271 ms
219,952 KB
testcase_11 AC 300 ms
220,496 KB
testcase_12 AC 136 ms
80,952 KB
testcase_13 AC 913 ms
270,956 KB
testcase_14 AC 709 ms
247,240 KB
testcase_15 AC 163 ms
119,456 KB
testcase_16 AC 183 ms
117,188 KB
testcase_17 AC 168 ms
133,620 KB
testcase_18 AC 129 ms
85,968 KB
testcase_19 AC 321 ms
126,908 KB
testcase_20 AC 441 ms
164,620 KB
testcase_21 AC 129 ms
82,996 KB
testcase_22 AC 191 ms
148,248 KB
testcase_23 AC 174 ms
134,872 KB
testcase_24 AC 542 ms
226,548 KB
testcase_25 AC 152 ms
92,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,v,sy,sx,gy,gx = map(int,input().split())
b = [list(map(int,input().split())) for _ in range(n)]
v = min(v,1800)
INF = 10**9
d = [[[INF]*(v+1) for _ in range(n)] for _ in range(n)]
mv = [[-1]*n for _ in range(n)]
mv[sx-1][sy-1] = v
d[sx-1][sy-1][v] = 0
gx -= 1; gy -= 1
from collections import deque
q = deque([(v,sx-1,sy-1)])

while q:
    v,x,y = q.popleft()
    if x==gx and y==gy:
        print(d[x][y][v])
        exit()
    dv = d[x][y][v]
    for nx,ny in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
        if 0 <= nx < n and 0 <= ny < n:
            nv = v - b[nx][ny]
            if nv <= 0: continue
            if dv+1 < d[nx][ny][nv] and mv[nx][ny] < nv:
                mv[nx][ny] = nv
                d[nx][ny][nv] = dv+1
                q.append((nv,nx,ny))

print(-1)
0