結果

問題 No.34 砂漠の行商人
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-15 20:49:43
言語 Python2
(2.7.18)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 694 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 6,716 KB
実行使用メモリ 6,876 KB
最終ジャッジ日時 2023-09-10 18:55:42
合計ジャッジ時間 3,721 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,452 KB
testcase_01 AC 13 ms
6,472 KB
testcase_02 AC 15 ms
6,228 KB
testcase_03 AC 12 ms
6,244 KB
testcase_04 AC 35 ms
6,452 KB
testcase_05 AC 42 ms
6,448 KB
testcase_06 AC 29 ms
6,324 KB
testcase_07 AC 83 ms
6,360 KB
testcase_08 AC 96 ms
6,456 KB
testcase_09 AC 73 ms
6,568 KB
testcase_10 AC 35 ms
6,592 KB
testcase_11 AC 54 ms
6,668 KB
testcase_12 AC 20 ms
6,232 KB
testcase_13 AC 183 ms
6,876 KB
testcase_14 AC 182 ms
6,776 KB
testcase_15 AC 15 ms
6,432 KB
testcase_16 AC 32 ms
6,592 KB
testcase_17 AC 15 ms
6,416 KB
testcase_18 AC 16 ms
6,192 KB
testcase_19 AC 84 ms
6,656 KB
testcase_20 AC 126 ms
6,732 KB
testcase_21 AC 18 ms
6,564 KB
testcase_22 AC 21 ms
6,460 KB
testcase_23 AC 15 ms
6,320 KB
testcase_24 AC 142 ms
6,628 KB
testcase_25 AC 31 ms
6,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,V,Sy,Sx,Gy,Gx = map(int,raw_input().split())
L=[]
for i in range(N):
    line = map(int,raw_input().split())
    L.append(line)

que=deque([(0,Sx-1,Sy-1,V)])

arrived=[[0 for i in range(N)]for j in range(N)]
dxs=[1,0,-1,0]
dys=[0,1,0,-1]
while que:
    dist,x,y,v = que.popleft()
    if arrived[x][y]>v:
        continue
    arrived[x][y]=v
    #print dist,y,x,v
    if (x,y)==(Gx-1,Gy-1):
        print dist
        exit()
    for dx,dy in zip(dxs,dys):
        nx,ny=x+dx,y+dy
        if nx>=0 and ny >= 0 and nx <N and ny <N and arrived[nx][ny]<v-L[nx][ny] :
            arrived[nx][ny]=v-L[nx][ny]
            que.append((dist+1,nx,ny,v-L[nx][ny]))
print -1
0