結果

問題 No.34 砂漠の行商人
ユーザー mkawa2mkawa2
提出日時 2020-01-08 09:49:49
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 999 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 284,084 KB
最終ジャッジ日時 2023-08-15 00:19:03
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,644 KB
testcase_01 AC 77 ms
71,372 KB
testcase_02 AC 648 ms
94,740 KB
testcase_03 AC 77 ms
71,480 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    n,v,sj,si,gj,gi=MI()
    sj, si, gj, gi=sj-1,si-1,gj-1,gi-1
    ll=LLI(n)
    maxhp=[[0]*n for _ in range(n)]
    bfs=[]
    #[距離,体力,行,列]
    heappush(bfs,[0,v,si,sj])
    while bfs:
        dist,hp,i,j=heappop(bfs)
        maxhp[i][j]=hp
        for di,dj in dij:
            ni,nj=i+di,j+dj
            if ni<0 or nj<0 or ni>=n or nj>=n:continue
            nhp=hp-ll[ni][nj]
            if nhp<=maxhp[ni][nj]:continue
            if (ni, nj) == (gi, gj):
                print(dist+1)
                exit()
            heappush(bfs,[dist+1,nhp,ni,nj])
    print(-1)

main()
0