結果

問題 No.34 砂漠の行商人
ユーザー convexineqconvexineq
提出日時 2021-01-17 04:04:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 411 ms / 5,000 ms
コード長 576 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 147,084 KB
最終ジャッジ日時 2024-05-06 17:37:10
合計ジャッジ時間 3,824 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,664 KB
testcase_01 AC 40 ms
55,196 KB
testcase_02 AC 52 ms
64,688 KB
testcase_03 AC 39 ms
54,788 KB
testcase_04 AC 79 ms
76,844 KB
testcase_05 AC 76 ms
76,784 KB
testcase_06 AC 59 ms
68,148 KB
testcase_07 AC 92 ms
78,332 KB
testcase_08 AC 99 ms
79,224 KB
testcase_09 AC 155 ms
89,568 KB
testcase_10 AC 63 ms
76,884 KB
testcase_11 AC 79 ms
77,224 KB
testcase_12 AC 61 ms
72,056 KB
testcase_13 AC 411 ms
147,084 KB
testcase_14 AC 307 ms
117,112 KB
testcase_15 AC 51 ms
66,416 KB
testcase_16 AC 69 ms
76,720 KB
testcase_17 AC 49 ms
63,396 KB
testcase_18 AC 54 ms
67,020 KB
testcase_19 AC 139 ms
87,948 KB
testcase_20 AC 191 ms
97,100 KB
testcase_21 AC 53 ms
66,852 KB
testcase_22 AC 55 ms
69,408 KB
testcase_23 AC 52 ms
65,240 KB
testcase_24 AC 218 ms
102,052 KB
testcase_25 AC 67 ms
76,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,v,sy,sx,gy,gx = map(int,input().split())
b = [list(map(int,input().split())) for _ in range(n)]
mv = [[-1]*n for _ in range(n)]
mv[sx-1][sy-1] = v
from collections import deque
q = deque([(0,v,sx-1,sy-1)])
while q:
    dv,v,x,y = q.popleft()
    if x==gx-1 and y==gy-1:
        print(dv)
        exit()
    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 mv[nx][ny] < nv:
                mv[nx][ny] = nv
                q.append((dv+1,nv,nx,ny))
print(-1)
0