結果

問題 No.134 走れ!サブロー君
ユーザー lloyzlloyz
提出日時 2023-10-09 01:49:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 5,000 ms
コード長 1,119 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 87,328 KB
実行使用メモリ 80,828 KB
最終ジャッジ日時 2023-10-09 01:49:50
合計ジャッジ時間 2,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,180 KB
testcase_01 AC 72 ms
71,604 KB
testcase_02 AC 73 ms
71,424 KB
testcase_03 AC 103 ms
77,084 KB
testcase_04 AC 128 ms
78,336 KB
testcase_05 AC 146 ms
78,824 KB
testcase_06 AC 163 ms
79,500 KB
testcase_07 AC 164 ms
79,756 KB
testcase_08 AC 187 ms
80,764 KB
testcase_09 AC 184 ms
80,828 KB
testcase_10 AC 74 ms
71,212 KB
testcase_11 AC 71 ms
71,528 KB
testcase_12 AC 70 ms
71,572 KB
testcase_13 AC 70 ms
71,440 KB
testcase_14 AC 69 ms
71,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

x0, y0 = map(int, input().split())
n = int(input())
XYW = []
for _ in range(n):
    x, y, w = map(float, input().split())
    x = int(x)
    y = int(y)
    XYW.append((x, y, w))

W = [0 for _ in range(1 << n)]
for bit in range(1 << n):
    w = 0
    for i in range(n):
        if (bit >> i) & 1 == 0:
            w += XYW[i][2]
    W[bit] = w
INF = 10**18
DP = [[INF for _ in range(n)] for _ in range(1 << n)]
for i in range(n):
    xi, yi, w = XYW[i]
    bit = 1 << i
    DP[bit][i] = (W[0] + 100) * (abs(xi - x0) + abs(yi - y0)) / 120 + w
for bit in range(1 << n):
    source, sink = [], []
    for i in range(n):
        if (bit >> i) & 1 == 0:
            sink.append(i)
        else:
            source.append(i)
    w = W[bit]
    for s in source:
        xs, ys = XYW[s][:2]
        for t in sink:
            xt, yt, ww = XYW[t]
            nbit = bit | (1 << t)
            DP[nbit][t] = min(DP[nbit][t], DP[bit][s] + (100 + w) * (abs(xt - xs) + abs(yt - ys)) / 120 + ww)
ans = INF
for i in range(n):
    xi, yi = XYW[i][:2]
    ans = min(ans, DP[-1][i] + 100 * (abs(x0 - xi) + abs(y0 - yi)) / 120)
print(ans)
0