結果

問題 No.134 走れ!サブロー君
ユーザー ckawatakckawatak
提出日時 2018-12-12 09:04:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 402 ms / 5,000 ms
コード長 1,127 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 79,252 KB
最終ジャッジ日時 2023-10-25 08:20:22
合計ジャッジ時間 2,790 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,476 KB
testcase_01 AC 55 ms
64,312 KB
testcase_02 AC 38 ms
53,480 KB
testcase_03 AC 89 ms
76,060 KB
testcase_04 AC 98 ms
76,392 KB
testcase_05 AC 116 ms
76,708 KB
testcase_06 AC 150 ms
76,908 KB
testcase_07 AC 225 ms
77,760 KB
testcase_08 AC 402 ms
79,252 KB
testcase_09 AC 392 ms
79,232 KB
testcase_10 AC 37 ms
53,480 KB
testcase_11 AC 38 ms
53,480 KB
testcase_12 AC 37 ms
53,480 KB
testcase_13 AC 38 ms
53,480 KB
testcase_14 AC 38 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(dp[0][0])
0