結果

問題 No.34 砂漠の行商人
ユーザー szkhtsszkhts
提出日時 2021-07-21 14:13:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 9,104 KB
最終ジャッジ日時 2023-09-24 13:07:42
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,624 KB
testcase_01 AC 19 ms
8,568 KB
testcase_02 AC 23 ms
8,684 KB
testcase_03 AC 19 ms
8,564 KB
testcase_04 AC 52 ms
8,664 KB
testcase_05 AC 53 ms
8,724 KB
testcase_06 AC 41 ms
8,748 KB
testcase_07 AC 102 ms
8,756 KB
testcase_08 AC 125 ms
8,812 KB
testcase_09 AC 90 ms
8,872 KB
testcase_10 AC 40 ms
8,812 KB
testcase_11 AC 61 ms
9,104 KB
testcase_12 AC 26 ms
8,644 KB
testcase_13 AC 221 ms
9,068 KB
testcase_14 AC 209 ms
9,004 KB
testcase_15 AC 20 ms
8,768 KB
testcase_16 AC 40 ms
8,748 KB
testcase_17 AC 20 ms
8,724 KB
testcase_18 AC 22 ms
8,748 KB
testcase_19 AC 102 ms
8,784 KB
testcase_20 AC 149 ms
8,888 KB
testcase_21 AC 185 ms
9,008 KB
testcase_22 AC 26 ms
8,844 KB
testcase_23 AC 20 ms
8,672 KB
testcase_24 AC 181 ms
8,952 KB
testcase_25 AC 38 ms
8,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,V,Sx,Sy,Gx,Gy = map(int,input().split())
Sx -= 1
Sy -= 1
Gx -= 1
Gy -= 1
sand = [list(map(int,input().split())) for i in range(N)]
dxy = [(1,0),(-1,0),(0,-1),(0,1)]
lstimes = [[0]*(N) for i in range(N)]
lscost = [[float('INF')]*N for i in range(N)]
lscost[Sy][Sx] = 0
d = collections.deque([(Sy,Sx)])
while d:
    x,y = d.popleft()
    if x == Gy and y == Gx:
        if lscost[x][y] < V:
            print(lstimes[x][y])
            exit()
    for dx,dy in dxy:
        if 0<= x+dx < N and 0 <= y+dy < N:
            if lscost[x+dx][y+dy] > lscost[x][y] + sand[x+dx][y+dy]:
                lscost[x+dx][y+dy] = lscost[x][y] + sand[x+dx][y+dy]
                lstimes[x+dx][y+dy] = lstimes[x][y]+1
                d.append((x+dx,y+dy))
print(-1)
0