結果

問題 No.134 走れ!サブロー君
ユーザー nebukuro09nebukuro09
提出日時 2016-10-06 14:55:51
言語 Python2
(2.7.18)
結果
AC  
実行時間 462 ms / 5,000 ms
コード長 711 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 16,104 KB
最終ジャッジ日時 2024-05-01 13:55:46
合計ジャッジ時間 2,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,400 KB
testcase_01 AC 12 ms
6,400 KB
testcase_02 AC 11 ms
6,272 KB
testcase_03 AC 17 ms
6,528 KB
testcase_04 AC 24 ms
6,784 KB
testcase_05 AC 44 ms
7,168 KB
testcase_06 AC 90 ms
8,448 KB
testcase_07 AC 201 ms
12,928 KB
testcase_08 AC 457 ms
16,104 KB
testcase_09 AC 462 ms
15,976 KB
testcase_10 AC 12 ms
6,528 KB
testcase_11 AC 12 ms
6,272 KB
testcase_12 AC 12 ms
6,272 KB
testcase_13 AC 11 ms
6,400 KB
testcase_14 AC 12 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

sakaya = map(int, raw_input().split())
N = input()
points = [map(float, raw_input().split()) for _ in xrange(N)]
W = sum(p[2] for p in points)

def cost(p1, p2, weight):
    T = (weight+100.0)/120
    return abs(p1[0]-p2[0])*T + abs(p1[1]-p2[1])*T

mem = {}
def rec(p, b, w):
    if (p, b) in mem:
        return mem[(p, b)]
    w -= points[p][2]
    if b == ((1 << N) - 1):
        return cost(sakaya, points[p], w)+points[p][2]

    m = float('inf')
    for i in xrange(N):
        if (1 << i) & b:
            continue
        m = min(m, rec(i, (1<<i)+b, w)+cost(points[p], points[i], w)+points[p][2])
    mem[(p, b)] = m
    return m

print min(rec(x, 1<<x, W)+cost(sakaya, points[x], W) for x in xrange(N))
0