結果

問題 No.34 砂漠の行商人
ユーザー roiti46roiti46
提出日時 2015-02-22 18:48:36
言語 Python2
(2.7.18)
結果
AC  
実行時間 172 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 6,664 KB
実行使用メモリ 6,616 KB
最終ジャッジ日時 2023-09-10 19:04:59
合計ジャッジ時間 2,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,952 KB
testcase_01 AC 10 ms
5,936 KB
testcase_02 AC 13 ms
5,936 KB
testcase_03 AC 10 ms
6,020 KB
testcase_04 AC 32 ms
6,004 KB
testcase_05 AC 38 ms
6,192 KB
testcase_06 AC 26 ms
5,984 KB
testcase_07 AC 74 ms
6,008 KB
testcase_08 AC 88 ms
6,216 KB
testcase_09 AC 66 ms
6,300 KB
testcase_10 AC 31 ms
6,208 KB
testcase_11 AC 50 ms
6,296 KB
testcase_12 AC 18 ms
6,080 KB
testcase_13 AC 172 ms
6,404 KB
testcase_14 AC 171 ms
6,616 KB
testcase_15 AC 13 ms
5,936 KB
testcase_16 AC 29 ms
6,088 KB
testcase_17 AC 13 ms
6,068 KB
testcase_18 AC 13 ms
6,040 KB
testcase_19 AC 77 ms
6,512 KB
testcase_20 AC 118 ms
6,476 KB
testcase_21 AC 16 ms
6,068 KB
testcase_22 AC 19 ms
6,148 KB
testcase_23 AC 13 ms
6,108 KB
testcase_24 AC 133 ms
6,460 KB
testcase_25 AC 29 ms
6,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

dxy = zip([1,0,-1,0],[0,1,0,-1])
N,V,Sx,Sy,Gx,Gy = map(int,raw_input().split())
Sx,Sy,Gx,Gy = Sx-1,Sy-1,Gx-1,Gy-1
L = [map(int,raw_input().split()) for i in xrange(N)]
HP = [[0]*N for i in xrange(N)]
que = [[Sx,Sy,V,0]]
while que:
    x,y,v,d = que.pop(0)
    if (x,y) == (Gx,Gy):
        print d
        break
    if HP[y][x] > v: continue
    HP[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] > HP[ny][nx]:
            HP[ny][nx] = v-L[ny][nx]
            que.append([nx,ny,v-L[ny][nx],d+1])
else:
    print -1
0