結果

問題 No.134 走れ!サブロー君
ユーザー 👑 rin204rin204
提出日時 2022-11-03 00:53:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 5,000 ms
コード長 800 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 81,392 KB
最終ジャッジ日時 2023-09-24 11:34:54
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,380 KB
testcase_01 AC 90 ms
76,880 KB
testcase_02 AC 74 ms
71,496 KB
testcase_03 AC 116 ms
77,748 KB
testcase_04 AC 120 ms
77,932 KB
testcase_05 AC 130 ms
78,428 KB
testcase_06 AC 150 ms
78,536 KB
testcase_07 AC 208 ms
79,384 KB
testcase_08 AC 327 ms
81,240 KB
testcase_09 AC 330 ms
81,392 KB
testcase_10 AC 73 ms
71,236 KB
testcase_11 AC 75 ms
71,388 KB
testcase_12 AC 74 ms
71,680 KB
testcase_13 AC 75 ms
71,564 KB
testcase_14 AC 74 ms
71,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

x0, y0 = map(float, input().split())
n = int(input())
xyw = [[x0, y0, 0]] + [list(map(float, input().split())) for _ in range(n)]
n += 1

def nex(bit, i, j):
    w = 0
    for k in range(n):
        if not bit >> k & 1:
            w += xyw[k][2]
    xi, yi, _ = xyw[i]
    xj, yj, _ = xyw[j]
    d = abs(xi - xj) + abs(yi - yj)
    return d * (w + 100) / 120

dp = [[1e18] * n for _ in range(1 << n)]
for i in range(1, n):
    dp[1 << i][i] = nex(0, 0, i) + xyw[i][2]

for bit in range(1, 1 << n):
    for i in range(n):
        if not bit >> i & 1:
            continue
        for j in range(n):
            if bit >> j & 1 and i != j:
                tmp = dp[bit ^ (1 << j)][i] + nex(bit ^ (1 << j), i, j) + xyw[j][2]
                dp[bit][j] = min(dp[bit][j], tmp)

ans = dp[-1][0]
print(ans)
0