結果

問題 No.34 砂漠の行商人
ユーザー pluto77pluto77
提出日時 2019-01-08 09:59:10
言語 Python2
(2.7.18)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 497 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 6,636 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-08-15 16:38:47
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
5,856 KB
testcase_01 AC 9 ms
5,916 KB
testcase_02 AC 12 ms
5,844 KB
testcase_03 AC 9 ms
5,940 KB
testcase_04 AC 27 ms
5,900 KB
testcase_05 AC 33 ms
5,940 KB
testcase_06 AC 24 ms
5,896 KB
testcase_07 AC 70 ms
5,992 KB
testcase_08 AC 77 ms
6,104 KB
testcase_09 AC 58 ms
6,116 KB
testcase_10 AC 30 ms
6,288 KB
testcase_11 AC 48 ms
6,476 KB
testcase_12 AC 17 ms
6,004 KB
testcase_13 AC 158 ms
6,504 KB
testcase_14 AC 151 ms
6,428 KB
testcase_15 AC 12 ms
5,920 KB
testcase_16 AC 25 ms
6,012 KB
testcase_17 AC 12 ms
6,012 KB
testcase_18 AC 11 ms
6,048 KB
testcase_19 AC 67 ms
6,296 KB
testcase_20 AC 103 ms
6,448 KB
testcase_21 AC 14 ms
6,096 KB
testcase_22 AC 17 ms
6,140 KB
testcase_23 AC 11 ms
5,896 KB
testcase_24 AC 118 ms
6,312 KB
testcase_25 AC 26 ms
6,012 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