結果

問題 No.34 砂漠の行商人
ユーザー szkhtsszkhts
提出日時 2023-03-19 08:02:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 230 ms / 5,000 ms
コード長 818 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 11,832 KB
実行使用メモリ 10,728 KB
最終ジャッジ日時 2023-10-18 17:40:50
合計ジャッジ時間 3,645 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,180 KB
testcase_01 AC 30 ms
10,180 KB
testcase_02 AC 34 ms
10,192 KB
testcase_03 AC 29 ms
10,192 KB
testcase_04 AC 61 ms
10,264 KB
testcase_05 AC 66 ms
10,280 KB
testcase_06 AC 52 ms
10,240 KB
testcase_07 AC 117 ms
10,308 KB
testcase_08 AC 135 ms
10,372 KB
testcase_09 AC 100 ms
10,328 KB
testcase_10 AC 53 ms
10,432 KB
testcase_11 AC 75 ms
10,728 KB
testcase_12 AC 39 ms
10,260 KB
testcase_13 AC 230 ms
10,604 KB
testcase_14 AC 222 ms
10,560 KB
testcase_15 AC 32 ms
10,264 KB
testcase_16 AC 52 ms
10,264 KB
testcase_17 AC 32 ms
10,296 KB
testcase_18 AC 33 ms
10,200 KB
testcase_19 AC 115 ms
10,428 KB
testcase_20 AC 160 ms
10,464 KB
testcase_21 AC 206 ms
10,528 KB
testcase_22 AC 38 ms
10,372 KB
testcase_23 AC 32 ms
10,296 KB
testcase_24 AC 188 ms
10,464 KB
testcase_25 AC 51 ms
10,300 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