結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
![]() |
提出日時 | 2020-01-08 09:49:49 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 999 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 82,476 KB |
実行使用メモリ | 380,520 KB |
最終ジャッジ日時 | 2024-11-23 02:19:35 |
合計ジャッジ時間 | 111,539 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 TLE * 18 |
ソースコード
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()