結果

問題 No.34 砂漠の行商人
ユーザー kohei2019kohei2019
提出日時 2021-02-18 02:38:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 743 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 78,672 KB
最終ジャッジ日時 2023-10-12 12:19:12
合計ジャッジ時間 5,192 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,336 KB
testcase_01 AC 91 ms
71,520 KB
testcase_02 AC 115 ms
77,948 KB
testcase_03 AC 93 ms
71,604 KB
testcase_04 AC 114 ms
77,868 KB
testcase_05 AC 117 ms
78,128 KB
testcase_06 AC 115 ms
78,048 KB
testcase_07 AC 123 ms
78,212 KB
testcase_08 AC 128 ms
78,592 KB
testcase_09 AC 125 ms
78,672 KB
testcase_10 AC 114 ms
77,992 KB
testcase_11 AC 113 ms
77,844 KB
testcase_12 AC 114 ms
77,948 KB
testcase_13 AC 132 ms
78,580 KB
testcase_14 AC 131 ms
78,588 KB
testcase_15 AC 106 ms
77,608 KB
testcase_16 AC 117 ms
77,828 KB
testcase_17 AC 98 ms
76,784 KB
testcase_18 AC 110 ms
77,432 KB
testcase_19 AC 125 ms
78,444 KB
testcase_20 AC 128 ms
78,624 KB
testcase_21 AC 133 ms
78,548 KB
testcase_22 AC 115 ms
78,124 KB
testcase_23 AC 107 ms
77,840 KB
testcase_24 AC 131 ms
78,380 KB
testcase_25 AC 116 ms
78,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,V,Sx,Sy,Gx,Gy = map(int,input().split())
lsL = [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-1][Sx-1] = 0
d = collections.deque([(Sy-1,Sx-1)])
while d:
    x,y = d.popleft()
    if x == Gy-1 and y == Gx-1:
        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] + lsL[x+dx][y+dy]:
                lscost[x+dx][y+dy] = lscost[x][y] + lsL[x+dx][y+dy]
                lstimes[x+dx][y+dy] = lstimes[x][y]+1
                d.append((x+dx,y+dy))
print(-1)
0