結果

問題 No.34 砂漠の行商人
ユーザー pluto77pluto77
提出日時 2019-01-08 09:59:10
言語 Python2
(2.7.18)
結果
AC  
実行時間 191 ms / 5,000 ms
コード長 497 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-05-03 03:39:46
合計ジャッジ時間 2,699 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,144 KB
testcase_01 AC 11 ms
6,144 KB
testcase_02 AC 14 ms
6,272 KB
testcase_03 AC 11 ms
6,144 KB
testcase_04 AC 35 ms
6,400 KB
testcase_05 AC 42 ms
6,400 KB
testcase_06 AC 30 ms
6,400 KB
testcase_07 AC 84 ms
6,272 KB
testcase_08 AC 97 ms
6,400 KB
testcase_09 AC 72 ms
6,656 KB
testcase_10 AC 35 ms
6,656 KB
testcase_11 AC 54 ms
6,656 KB
testcase_12 AC 19 ms
6,272 KB
testcase_13 AC 191 ms
6,528 KB
testcase_14 AC 188 ms
6,656 KB
testcase_15 AC 14 ms
6,400 KB
testcase_16 AC 31 ms
6,272 KB
testcase_17 AC 14 ms
6,272 KB
testcase_18 AC 14 ms
6,144 KB
testcase_19 AC 86 ms
6,784 KB
testcase_20 AC 132 ms
6,784 KB
testcase_21 AC 17 ms
6,528 KB
testcase_22 AC 20 ms
6,528 KB
testcase_23 AC 14 ms
6,272 KB
testcase_24 AC 149 ms
6,656 KB
testcase_25 AC 30 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki34

n,v,sx,sy,gx,gy=map(int,raw_input().split())
sx,sy,gx,gy=sx-1,sy-1,gx-1,gy-1
l=[]
for i in xrange(n):
 l.append(map(int,raw_input().split()))
p=[[0]*n for i in xrange(n)]
dxy=((1,0),(0,1),(-1,0),(0,-1))
q=[[sx,sy,v,0]]
while q:
 x,y,v,d=q.pop(0)
 if (x,y)==(gx,gy):
  print d
  break
 if p[y][x]>v:
  continue
 p[y][x]=v
 for dx,dy in dxy:
  nx,ny=x+dx,y+dy
  if 0<=nx<n and 0<=ny<n and v-l[ny][nx]>p[ny][nx]:
   p[ny][nx]=v-l[ny][nx]
   q.append([nx,ny,v-l[ny][nx],d+1])
else:
 print -1
0