結果

問題 No.34 砂漠の行商人
ユーザー convexineqconvexineq
提出日時 2021-01-17 03:46:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 864 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 269,440 KB
最終ジャッジ日時 2024-05-06 17:18:49
合計ジャッジ時間 6,500 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,144 KB
testcase_01 AC 44 ms
53,888 KB
testcase_02 AC 63 ms
66,432 KB
testcase_03 AC 45 ms
54,144 KB
testcase_04 AC 97 ms
79,488 KB
testcase_05 AC 100 ms
81,152 KB
testcase_06 AC 68 ms
70,400 KB
testcase_07 AC 130 ms
84,224 KB
testcase_08 AC 153 ms
88,576 KB
testcase_09 AC 333 ms
168,960 KB
testcase_10 AC 233 ms
218,240 KB
testcase_11 AC 252 ms
219,268 KB
testcase_12 AC 90 ms
79,744 KB
testcase_13 AC 864 ms
269,440 KB
testcase_14 AC 627 ms
245,376 KB
testcase_15 AC 113 ms
113,792 KB
testcase_16 AC 141 ms
115,072 KB
testcase_17 AC 106 ms
113,240 KB
testcase_18 AC 98 ms
84,096 KB
testcase_19 AC 295 ms
124,928 KB
testcase_20 AC 403 ms
164,096 KB
testcase_21 AC 79 ms
73,856 KB
testcase_22 AC 136 ms
136,276 KB
testcase_23 AC 123 ms
132,992 KB
testcase_24 AC 512 ms
224,640 KB
testcase_25 AC 99 ms
88,320 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