結果

問題 No.34 砂漠の行商人
ユーザー szkhtsszkhts
提出日時 2023-03-19 08:02:06
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 253 ms / 5,000 ms
コード長 818 bytes
コンパイル時間 77 ms
使用メモリ 9,816 KB
最終ジャッジ日時 2023-03-19 08:02:10
合計ジャッジ時間 4,225 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 19 ms
8,152 KB
testcase_01 AC 18 ms
8,052 KB
testcase_02 AC 23 ms
8,124 KB
testcase_03 AC 18 ms
7,988 KB
testcase_04 AC 56 ms
9,772 KB
testcase_05 AC 61 ms
9,736 KB
testcase_06 AC 51 ms
8,312 KB
testcase_07 AC 137 ms
9,708 KB
testcase_08 AC 139 ms
8,244 KB
testcase_09 AC 106 ms
8,300 KB
testcase_10 AC 46 ms
9,708 KB
testcase_11 AC 71 ms
8,792 KB
testcase_12 AC 30 ms
9,768 KB
testcase_13 AC 253 ms
9,756 KB
testcase_14 AC 244 ms
9,816 KB
testcase_15 AC 22 ms
8,216 KB
testcase_16 AC 45 ms
9,772 KB
testcase_17 AC 21 ms
9,640 KB
testcase_18 AC 27 ms
8,112 KB
testcase_19 AC 134 ms
8,252 KB
testcase_20 AC 172 ms
8,496 KB
testcase_21 AC 219 ms
8,488 KB
testcase_22 AC 28 ms
8,328 KB
testcase_23 AC 21 ms
9,756 KB
testcase_24 AC 200 ms
8,640 KB
testcase_25 AC 44 ms
8,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import sys

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)]
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])
            sys.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