結果

問題 No.134 走れ!サブロー君
ユーザー ckawatakckawatak
提出日時 2018-12-11 22:42:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,136 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,628 KB
実行使用メモリ 79,240 KB
最終ジャッジ日時 2023-10-24 12:51:30
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,480 KB
testcase_01 AC 50 ms
64,284 KB
testcase_02 AC 34 ms
53,480 KB
testcase_03 WA -
testcase_04 AC 89 ms
76,368 KB
testcase_05 WA -
testcase_06 AC 136 ms
76,880 KB
testcase_07 WA -
testcase_08 AC 364 ms
79,224 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 35 ms
53,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

X,Y = list(map(int, input().split(' ')))
N = int(input())

weights = [0]
customers = [(X,Y,0)]
for _ in range(N):
    x,y,weight = tuple(map(float, input().split(' ')))
    weights.append(weight)
    customers.append((x,y))

N = N + 1
W = sum(weights)
    
distances = []
for i in range(N):
    row = []
    for j in range(N):
        distance = abs(customers[i][0] - abs(customers[j][0])) + \
            abs(customers[i][1] - abs(customers[j][1]))
        row.append(distance)
    distances.append(row)

def time_to_take(weight):
    return (weight + 100) / 120

def weight(S, weights):
    weight = W
    i = 0
    while 0 < S:
        if S & 1 == 1:
            weight = weight - weights[i]
        S = S >> 1
        i = i + 1
    return weight

dp = []
for i in range(1 << N):
    dp.append([float('inf') for _ in range(N)])

dp[(1 << N) - 1][0] = 0

for S in reversed(range(0, (1 << N) - 1)):
    for v in range(N):
        for u in range(N):
            if not (S >> u & 1):
                dp[S][v] = min(dp[S][v], dp[S | 1 << u][u] + distances[v][u] * time_to_take(weight(S, weights)) + weights[u])

print("%.2f" % dp[0][0])
0