結果
| 問題 | No.34 砂漠の行商人 |
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2020-01-08 10:40:09 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 2,960 ms / 5,000 ms |
| コード長 | 1,028 bytes |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 16,452 KB |
| 最終ジャッジ日時 | 2024-11-23 02:22:26 |
| 合計ジャッジ時間 | 11,965 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import sys
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)]
now=[[v,si,sj]]
cnt=1
while now:
#print(now)
nxt=[]
for hp,i,j in now:
for ni,nj in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
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(cnt)
exit()
maxhp[ni][nj]=nhp
nxt.append([nhp,ni,nj])
now=nxt
cnt+=1
print(-1)
main()
mkawa2