Problem:
ルパン四世
怪盗「ルパン四世」は会津藩士を末裔とする美女「富士峰子」より、会津若松市に会津藩が残した軍資金が眠っていることを聞かされる。ルパンの長年の仲間である「石川越ェ門」の報告によれば、軍資金は千両箱に収められいくつかの蔵に保管されている。蔵に見張りはいないが厳重に施錠されている。しかし、越ェ門は彼が父から伝授された秘伝「鋼鉄斬り」の技を繰り出せば瞬時に蔵を破れるという。
残った問題は千両箱の運搬だ。体力のないルパンと越ェ門は千両箱を一つも持てない。そこで、頼りになる男「無限大介」に運搬を頼んだ。
すべての千両箱を運び出すために、ルパンは以下のような計画を立案した。
まず、ルパンの運転で最初の蔵へ行き、越ェ門と大介を降ろす。
越ェ門が蔵を破る
大介がすべての千両箱を運び出す
その千両箱を持ったままルパンが決めた次の蔵へ向かう
これを繰り返し、最後の蔵まで破り千両箱を運び出す。その間にルパンはヘリコプターを準備し最後の蔵で二人と千両箱を運び上げ脱出する。大介はどんなに重いものも運搬できるが、荷物の重さに応じて移動速度は遅くなる。ルパンは、このことを考慮して蔵を破る順番を決めなければならない。
ルパンに代わって、最初の蔵を破ってから最後の蔵に辿りつくまでの移動時間が最小となるような蔵を破る順番を出力するプログラムを作成してください。ただし、
蔵はすべて鶴ヶ城からまっすぐ北に走る通りに面している。蔵の数は高々 15 個であり、城からの距離は高々 10000 メートル以下である。
千両箱の重さはいずれもひとつ 20 キログラムである。それぞれの蔵に収められている千両箱の個数は 10000 個以下である。
蔵から蔵への移動は、通りに沿って地下に設置されている地下道を使う。
大介は
w
キログラムの荷物を運ぶのに、分速 2,000／(70 +
w
) メートルで移動する。
入力データは、それぞれの蔵について蔵の番号（100 以下の整数）と城からの距離（メートル）とその蔵に保管されている千両箱の個数が与えられる。
Input
入力は以下の形式で与えられます。
n
s
1
d
1
v
1
s
2
d
2
v
2
:
s
n
d
n
v
n
1 行目に蔵の個数
n
（
n
≤ 15）、続く
n
行に第
i
の蔵の情報が与えられます。蔵の情報として、蔵の番号
s
i
(1 ≤
s
i
≤ 100)、城からの距離
d
i
(1 ≤
d
i
≤ 10000)、 千両箱の数
v
i
(1 ≤
v
i
≤ 10000) が１行に与えられます。
Output
蔵を破る順番を１行に出力してください。蔵の番号を空白で区切ってください。
Sample Input 1
2
1 100 1
2 200 2
Output for the Sample Input 1
1 2
Sample Input 2
3
11 100 1
13 200 20
12 300 3
Output for the Sample Input 2
11 12 13
Sample Input 3
5
13 199 1
51 1000 1
37 350 10
27 300 2
99 200 1000
Output for the Sample Input 3
51 37 27 13 99

Submitted solutions:

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int n;
vector<int> dist, box;
vector<vector<int>> dp, bef, sum;

double solve(int bit, int lpos){
	if(dp[bit][lpos] != -1) return dp[bit][lpos];
	if(bit == (1 << lpos)){
		sum[bit][lpos] = box[lpos];
		return dp[bit][lpos] = 0;
	}
	int pre = (bit & ~(1 << lpos));
	double mn = 20000000, tmp;
	for(int i = 0; i < n; i++){
		if(pre & (1 << i)){
			tmp = solve(pre, i) + abs(dist[lpos] - dist[i]) * (70.0 + 20 * sum[pre][i]) / 2000.0;
			if(mn > tmp){
				mn = tmp;
				sum[bit][lpos] = sum[pre][i] + box[lpos];
				bef[bit][lpos] = i;
			}
		}
	}
	return dp[bit][lpos] = mn;
}

int main(){
	cin >> n;
	vector<int> num(n);
	dist.resize(n);
	box.resize(n);
	dp.assign((1 << n), vector<int>(n, -1));
	bef = dp;
	sum = dp;
	for(int i = 0; i < n; i++) cin >> num[i] >> dist[i] >> box[i];
	double mt = 20000000, t;
	int ans;
	for(int i = 0; i < n; i++){
		t = solve((1 << n) - 1, i);
		if(mt > t){
			mt = t;
			ans = i;
		}
	}
	vector<int> route;
	for(int tag = (1 << n) - 1, i = ans, k; i != -1;){
		route.push_back(num[i]);
		k = i;
		i = bef[tag][i];
		tag = (tag & ~(1 << k));
	}
	reverse(route.begin(), route.end());
	for(int i = 0; i < n - 1; i++) cout << route[i] << ' ';
	cout << route[n - 1] << endl;
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 13312
final_rank: 16

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> id(n), d(n), v(n);
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> d[i] >> v[i];
    }
    vector<vector<double>> dp(n, vector<double>(1 << n, 1e18));
    vector<vector<int>> pre(n, vector<int>(1 << n, -1));
    vector<int> sum(1 << n);
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if ((1 << j) & i) sum[i] += v[j];
        }
    }

    for (int i = 0; i < n; i++) {
        dp[i][1 << i] = 0;
    }
    for (int j = 0; j < (1 << n); j++) {
        for (int i = 0; i < n; i++) {
            if (dp[i][j] == 1e18) continue;
            for (int k = 0; k < n; k++) {
                if ((1 << k) & j) continue;
                double dist = abs(d[i] - d[k]);
                double tm = dist / 2000 * (70 + sum[j] * 20);
                double cost = dp[i][j] + tm;
                if (dp[k][(1 << k) + j] > cost) {
                    dp[k][(1 << k) + j] = cost;
                    pre[k][(1 << k) + j] = i;
                }
            }
        }
    }
    vector<int> res;
    int lst = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i].back() < dp[lst].back()) {
            lst = i;
        }
    }
    int bit = (1 << n) - 1;
    while (res.size() < n) {
        res.push_back(id[lst]);
        int nxt = pre[lst][bit];
        bit -= (1 << lst);
        lst = nxt;
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 8784
final_rank: 1

code_snippet: #include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){	

	int n;
	cin>>n;
	
	vector<int> s(n);
	vector<double> d(n),v(n);
	rep(i,n)cin>>s[i]>>d[i]>>v[i];
	
	vector dp(1<<n,vector<double>(n,1e18));
	vector pre(1<<n,vector<int>(n,-1));
	rep(i,n){
		dp[1<<i][i] = 0.0;
	}
	
	rep(i,1<<n){
		rep(j,n){
			if(dp[i][j]==1e18)continue;
			double w = 0.0;
			rep(k,n){
				if((i>>k)&1)w += v[k];
			}
			w *= 20.0;
			double V = 2000.0;
			V /= 70+w;
			rep(k,n){
				if((i>>k)&1)continue;
				int ii = i | (1<<k);
				int jj = k;
				double nv = dp[i][j];
				nv += abs(d[j]-d[k]) / V;
				if(dp[ii][jj]>nv){
					dp[ii][jj] = nv;
					pre[ii][jj] = j;
				}
			}
		}
	}
	int ii = 0;
	rep(i,n){
		if(dp.back()[i]<dp.back()[ii])ii = i;
	}
	vector<int> ans(1,ii);
	int x = 1<<n;
	x--;
	while(ans.size()!=n){
		int y = ii;
		ii = pre[x][ii];
		x ^= 1<<y;
		ans.insert(ans.begin(),ii);
	}
	rep(i,ans.size()){
		if(i!=0)cout<<' ';
		cout<<s[ans[i]];
	}
	cout<<endl;
	return 0;
	
}
accuracy: 1
time_ms: 20
memory_kb: 11272
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    //千両箱の重さはいずれもひとつ 20 キログラム
    vector<int> s(n), d(n), v(n);
    for(int i = 0; i < n; i++){
        cin >> s[i] >> d[i] >> v[i];
    }
    auto f = [&](int S){
        int w = 0;
        for(int i = 0; i < n; i++){
            if(S >> i & 1)w += v[i] * 20;
        }
        return 2000.0 / (70 + w);
    };
    vector<vector<double>> dp(1 << n, vector<double>(n, 1 << 30));
    vector<vector<int>> par(1 << n, vector<int>(n, -1));
    double V = f(0);
    for(int i = 0; i < n; i++){
        dp[1 << i][i] = d[i] / V;
    }
    for(int i = 1; i < (1 << n); i++){
        V = f(i);
        for(int j = 0; j < n; j++){
            if(~i >> j & 1)continue;
            for(int k = 0; k < n; k++){
                if(i >> k & 1)continue;
                if(dp[i][j] + abs(d[j] - d[k]) / V < dp[i | (1 << k)][k]){
                    dp[i | (1 << k)][k] = dp[i][j] + abs(d[j] - d[k]) / V;
                    par[i | (1 << k)][k] = j;
                }
            }
        }
    }
    int cur = 0;
    V = 1 << 30;
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        if(dp.back()[i] < V){
            V = dp.back()[i];
            cur = i;
        }
    }
    ans[n - 1] = s[cur];
    int S = (1 << n) - 1;
    for(int i = n - 1; i >= 1; i--){
        ans[i - 1] = s[par[S][cur]];
        S ^= 1 << cur;
        cur = par[S ^ (1 << cur)][cur];
    }
    for(int i = 0; i < n; i++){
        if(i)cout << " ";
        cout << ans[i];
    }
    cout << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 11244
final_rank: 4

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<climits>
#include<iomanip>
#include<cctype>
#include<sstream>
#include<regex>
#include<bitset>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int Mod=998244353;
const int inf=mod*mod;
const double eps=1e-9;
int dp[32768][15],pre[32768][15];
signed main(){
	int n,s[15],d[15],v[15];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s[i]>>d[i]>>v[i];
	for(int S=0;S<1<<n;S++){
		for(int i=0;i<n;i++){
			if(~S>>i&1)
				continue;
			if(S==1<<i)
				continue;
			dp[S][i]=inf;
			int pS=S&~(1<<i),sum=0;
			for(int j=0;j<n;j++)
				if(pS>>j&1)
					sum+=v[j];
			for(int j=0;j<n;j++){
				if(~pS>>j&1)
					continue;
				if(dp[pS][j]+sum*abs(d[i]-d[j])<dp[S][i]){
					dp[S][i]=dp[pS][j]+sum*abs(d[i]-d[j]);
					pre[S][i]=j;
				}
			}
		}
	}
	int S=(1<<n)-1,tmp=-1;
	vector<int>ans;
	for(int i=0;i<n;i++)
		if(tmp==-1||dp[S][i]<dp[S][tmp])
			tmp=i;
	while(S){
		ans.push_back(tmp);
		int pS=S&~(1<<tmp);
		tmp=pre[S][tmp];
		S=pS;
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<n;i++)
		cout<<s[ans[i]]<<(i==n-1?'\n':' ');
}
accuracy: 1
time_ms: 20
memory_kb: 11040
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using lli = long long int;
const lli inf = 1e18;

int main(){
    int n;
    cin >> n;
    vector<lli> s(n),d(n),v(n);
    for(int i=0; i<n; i++){
        cin >> s[i] >> d[i] >> v[i];
    }

    vector<vector<lli>> dp(1<<n, vector<lli>(n, inf));
    vector<vector<int>> prev(1<<n, vector<int>(n, -1));
    for(int i=0; i<n; i++){
        dp[1<<i][i] = 0;
        prev[1<<i][i] = i;
    }
    for(int i=1; i<(1<<n); i++){
        lli w = 0;
        for(int j=0; j<n; j++){
            if(i>>j&1) w += v[j];
        }
        w *= 20;
        // from j to k
        for(int j=0; j<n; j++){
            if(!(i>>j&1)) continue;
            for(int k=0; k<n; k++){
                if(i>>k&1) continue;
                int nmask = i | (1<<k);
                lli dist = abs(d[j]-d[k]);
                lli ncost = dp[i][j] +dist*(70+w);
                if(ncost >= dp[nmask][k]) continue;
                dp[nmask][k] = ncost;
                prev[nmask][k] = j;
            }
        }
    }

    int mask = (1<<n) -1;
    int last = min_element(dp[mask].begin(), dp[mask].end()) -dp[mask].begin();
    vector<int> ans;
    while(mask > 0){
        ans.push_back(s[last]);
        int nlast = prev[mask][last];
        mask ^= 1<<last;
        last = nlast;
    }
    reverse(ans.begin(), ans.end());
    for(int i=0; i<n-1; i++){
        cout << ans[i] << " ";
    }
    cout << ans.back() << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 11296
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N;
int Id[15], Dist[15], Weight[15];
int DpWeight[1 << 15], traceInfo[15][1 << 15];
double DpTime[15][1 << 15];

double getTime(double dist, double weight) {
	return dist * (70 + weight) / 2000.0;
}

double judge(int now, int visited) {
	double curTime,resTime;

	if (DpTime[now][visited] != -1) {
		return DpTime[now][visited];
	}
	if (visited == (1 << N) - 1) {
		return 0;
	}

	resTime = DBL_MAX;
	for (int i = 0; i < N; ++i) {
		if (((visited >> i) & 1) == 1) {
			continue;
		}
		curTime = judge(i, visited^(1<<i)) + getTime(abs(Dist[i] - Dist[now]), DpWeight[visited]);
		if (curTime < resTime) {
			resTime = curTime;
			traceInfo[now][visited] = i;
		}
	}

	return DpTime[now][visited] = resTime;
}

void solve(int limit) {
	int id;
	double timeMin, curTime;

	for (int i = 0; i < N; ++i) {
		fill(DpTime[i], DpTime[i] + limit, -1);
	}

	timeMin = DBL_MAX;
	for (int i = 0; i < N; ++i) {
		curTime = judge(i, 1 << i);
		if (curTime < timeMin) {
			timeMin = curTime;
			id = i;
		}
	}

	--limit;
	cout << Id[id];
	for (int i = 1 << id; i < limit; i^=(1<<id)) {
		id = traceInfo[id][i];
		cout << " " << Id[id];
	}
	cout << endl;
}

int main() {
	int limit;

	memset(DpWeight, 0, sizeof(DpWeight));
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> Id[i] >> Dist[i] >> Weight[i];
	}

	limit = 1 << N;
	for (int i = 1; i < limit; ++i) {
		for (int j = 0; j < N; ++j) {
			if (((i >> j) & 1) == 1) {
				DpWeight[i] += Weight[j] * 20;
			}
		}
	}
	solve(limit);

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8784
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N;
int Id[15], Dist[15], Weight[15];
int DpWeight[1 << 15], traceInfo[15][1 << 15];
double DpTime[15][1 << 15];

double getTime(double dist, double weight) {
	return dist * (70 + weight) / 2000.0;
}

double judge(int now, int visited) {
	double curTime,resTime;

	if (DpTime[now][visited] != -1) {
		return DpTime[now][visited];
	}
	if (visited == (1 << N) - 1) {
		return 0;
	}

	resTime = DBL_MAX;
	for (int i = 0; i < N; ++i) {
		if (((visited >> i) & 1) == 1) {
			continue;
		}
		curTime = judge(i, visited^(1<<i)) + getTime(abs(Dist[i] - Dist[now]), DpWeight[visited]);
		if (curTime < resTime) {
			resTime = curTime;
			traceInfo[now][visited] = i;
		}
	}

	return DpTime[now][visited] = resTime;
}

void solve(int limit) {
	int id;
	double timeMin, curTime;

	for (int i = 0; i < N; ++i) {
		fill(DpTime[i], DpTime[i] + limit, -1);
	}

	timeMin = DBL_MAX;
	for (int i = 0; i < N; ++i) {
		curTime = judge(i, 1 << i);
		if (curTime < timeMin) {
			timeMin = curTime;
			id = i;
		}
	}

	--limit;
	cout << Id[id];
	for (int i = 1 << id; i < limit; i^=(1<<id)) {
		id = traceInfo[id][i];
		cout << " " << Id[id];
	}
	cout << endl;
}

int main() {
	int limit;

	memset(DpWeight, 0, sizeof(DpWeight));
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> Id[i] >> Dist[i] >> Weight[i];
	}

	limit = 1 << N;
	for (int i = 0; i < limit; ++i) {
		for (int j = 0; j < N; ++j) {
			if (((i >> j) & 1) == 1) {
				DpWeight[i] += Weight[j] * 20;
			}
		}
	}
	solve(limit);

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8768
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> bool chmin(T &a, const T &b){ return a > b && (a = b, true); }
template<class T> bool chmax(T &a, const T &b){ return a < b && (a = b, true); }

int main() {
    int n;
    cin >> n;
    vector<int> s(n), d(n), v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d %d", &s[i], &d[i], &v[i]);
    }
    vector<int> S(1 << n, 7);
    for (int i = 0; i < 1 << n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i & (1 << j)) S[i] += 2*v[j];
        }
    }
    auto dp = make_v(n, 1 << n, INF<ll>);
    auto prv = make_v(n, 1 << n, 0);
    for (int i = 0; i < n; ++i) {
        dp[i][1 << i] = 0;
    }
    for (int j = 0; j < 1 << n; ++j) {
        for (int i = 0; i < n; ++i) {
            if(dp[i][j] == INF<ll>) continue;
            for (int k = 0; k < n; ++k) {
                if(!(j & (1 << k))) {
                    if(chmin(dp[k][j^(1 << k)], dp[i][j]+S[j]*abs(d[i]-d[k]))){
                        prv[k][j^(1 << k)] = i;
                    }
                }
            }
        }
    }
    stack<int> ans;
    int b = 0, a = (1 << n)-1;
    for (int i = 0; i < n; ++i) if(dp[i][a] < dp[b][a]) b = i;
    while(a){
        ans.emplace(b);
        int x = prv[b][a];
        a -= 1 << b; b = x;
    }
    while(!ans.empty()){
        printf("%d", s[ans.top()]);
        ans.pop();
        if(!ans.empty()) printf(" ");
    }
    puts("");
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 8852
final_rank: 2

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
struct Warehouse {
	int id, position, count;
};
long long int min_cost(const int state, const int current, const long long int weight, const std::vector<Warehouse>& warehouses, std::vector<std::vector<long long int>>& memo) {
	if (state == memo.size() - 1) return 0;
	if (memo[state][current] >= 0) return memo[state][current];
	long long int min_time = LLONG_MAX;
	for (auto i = 0; i < warehouses.size(); ++i) if ((state & (1 << i)) == 0) {
		min_time = std::min(min_time, min_cost(state | (1 << i), i, weight + warehouses[i].count * 20, warehouses, memo) + std::abs(warehouses[current].position - warehouses[i].position) * weight);
	}
	return memo[state][current] = min_time;
}
std::vector<int> cal_min_route(const std::vector<Warehouse>& warehouse) {
	std::vector<std::vector<long long int>> memo(1 << warehouse.size(), std::vector<long long int>(warehouse.size(), -1));
	std::vector<int> result; result.reserve(warehouse.size());
	int state = 0;
	long long int default_weight = 70;
	int current_pos = 0;
	for (auto _i = 0; _i < warehouse.size(); ++_i) {
		long long int min = LLONG_MAX;
		int min_pos = 0;
		for (auto i = 0; i < warehouse.size(); ++i) if ((state & (1 << i)) == 0) {
			const auto temp = min_cost(state | (1 << i), i, default_weight + warehouse[i].count * 20, warehouse, memo) + (result.empty() ? 0.0 : (std::abs(current_pos - warehouse[i].position) * default_weight));
			if (min > temp) {
				min = temp;
				min_pos = i;
			}
		}
		result.push_back(warehouse[min_pos].id);
		state |= 1 << min_pos;
		default_weight += warehouse[min_pos].count * 20;
		current_pos = warehouse[min_pos].position;
	}
	return result;
}
int main() {
	int n; std::cin >> n;
	std::vector<Warehouse> warehourse(n); for (auto& w : warehourse) std::cin >> w.id >> w.position >> w.count;
	auto result = cal_min_route(warehourse);
	for (auto i = 0; i < n; ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << result[i];
	}
	std::cout << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 7528
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n, d[15], s[15], v[15], w[1<<15], pre[15][1<<15];
double dp[15][1<<15];  // dp[現在地][すでに訪れたものの集合]

double t(int l, int S){
    return double(l)/(double(2000)/(70+w[S]*20));
}

double rec(int now, int S){
    if(dp[now][S] != -1) return dp[now][S];
    if(S == (1<<n)-1) return 0;

    double res = DBL_MAX;
    for(int i=0;i<n;i++){
        if((S>>i)&1) continue;
        double tmp = rec(i, S^(1<<i)) + t(abs(d[i]-d[now]), S);
        if(tmp < res){
            res = tmp;
            pre[now][S] = i;
        }
    }
    return dp[now][S] = res;
}

int main() {
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s[i] >> d[i] >> v[i];
    }
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                w[i] += v[j];
            }
        }
    }
    for(int i=0;i<n;i++) fill(dp[i], dp[i]+(1<<n), -1);
    int id = 0;
    double tmin = DBL_MAX;
    for(int i=0;i<n;i++){
        if(rec(i, 1<<i) < tmin){
            tmin = rec(i, 1<<i);
            id = i;
        }
    }
    cout << s[id];
    for(int S=1<<id; S<(1<<n)-1; S ^= 1<<id){
        id = pre[id][S];
        cout << " " << s[id];
    }
    cout << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8720
final_rank: 8

code_snippet: #include<iostream>
#include<vector>
#include<cfloat>
#include<algorithm>
using namespace std;

const double INF = DBL_MAX;

int main(){
    int n;
    cin >> n;
    vector<int> s(n), d(n), v(n);
    for(int i = 0; i < n; i++)  cin >> s[i] >> d[i] >> v[i];
    vector<vector<double>> dp(n, vector<double>(1<<n, INF));
    vector<vector<int>> back(n, vector<int>(1<<n, -1));
    for(int i = 0; i < n; i++){
        dp[i][1<<i] = 0;
    }
    for(int s = 0; s < 1<<n; s++){
        for(int i = 0; i < n; i++){
            if(((s>>i)&1) == 0) continue;
            double w = 0;
            for(int k = 0; k < n; k++)  if((s>>k)&1)    w += v[k];
            w *= 20;
            for(int j = 0; j < n; j++){
                if((s>>j)&1)    continue;
                if(dp[j][s|(1<<j)] > dp[i][s] + abs(d[i]-d[j])/2000.0*(70+w)){
                    dp[j][s|(1<<j)] = dp[i][s] + abs(d[i]-d[j])/2000.0*(70+w);
                    back[j][s|(1<<j)] = i;
                }
            }
        }
    }
    vector<int> ans;
    int pos = -1, bit = (1<<n)-1;
    double tim = INF;
    for(int j = 0; j < n; j++){
        if(dp[j][(1<<n)-1] < tim){
            tim = dp[j][bit];
            pos = j;
        }
    }
    while(pos != -1){
        ans.push_back(s[pos]);
        int nbit = bit^(1<<pos);
        pos = back[pos][bit];
        bit = nbit;
    }
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < n; i++){
        cout << ans[i] << " \n"[i==n-1];
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8656
final_rank: 7

code_snippet: #include <bits/stdc++.h>

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);


    int N;
    cin >> N;

    V<tuple<int, int, int>> v(N);
    FOR(i, 0, N) {
        int S, D, V;
        cin >> S >> D >> V;
        v[i] = make_tuple(S, D, V);
    }

    VV<int> dist(101, V<int>(101, 0));
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            int a, b, c, d, e, f;
            tie(a, b, c) = v[i];
            tie(d, e, f) = v[j];

            dist[i][j] = dist[j][i] = abs(b - e);
        }
    }

    vector<int> weight(1LL << N);
    FOR(b, 0, 1LL << N) {
        int w = 0;
        FOR(i, 0, N) {
            if (BIT_ON(b, i)) {
                w += get<2>(v[i]);
            }
        }
        weight[b] = w;
    }

    VV<int> pre(1LL << N, V<int>(N, -1));
    VV<double> dp(1LL << N, V<double>(N, INF));
    FOR(i, 0, N) {
        dp[1LL << i][i] = 0;
    }

    FOR(b, 0, 1LL << N) {
        FOR(i, 0, N) {
            FOR(j, 0, N) {
                if (BIT_ON(b, i) and not BIT_ON(b, j)) {
                    int d = dist[i][j];
                    int w = weight[b] * 20;
                    double cost = d / (2000.0 / (70.0 + w));
                    if (dp[b][i] + cost < dp[b | (1LL << j)][j]) {
                        dp[b | (1LL << j)][j] = dp[b][i] + cost;
                        pre[b | (1LL << j)][j] = i;
                    }
                }
            }
        }
    }

    int now = -1;
    double mini_cost = INF;
    FOR(i, 0, N) {
        if (dp[(1LL << N) - 1][i] < mini_cost) {
            mini_cost = dp[(1LL << N) - 1][i];
            now = i;
        }
    }

    vector<int> ans;
    auto b = (1LL << N) - 1;
    while (now != -1) {
        ans.emplace_back(get<0>(v[now]));
        int p = now;
        now = pre[b][now];
        b &= ~(1LL << p);
    }

    reverse(ALL(ans));
    print_vec(ans);

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 11248
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef pair<double, double> P;
typedef pair<P, int> P2;

#define INF 100000000

int n;
double s[55] = {0}, v[55] = {0}, d[55] = {0};
P2 dp[1 << 16][16];
vector<int>e;

void dfs(int now, int nowb){
	e.push_back(s[now]);
	if(dp[nowb][now].second == -1) return;
	dfs(dp[nowb][now].second, nowb & ~(1 << now));
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> s[i] >> d[i] >> v[i];
	for(int i = 0; i < (1 << n); i++){
		for(int j = 0; j < n; j++){
			dp[i][j].first.second = INF;
		}
	}
	for(int i = 0; i < (1 << n); i++){
		for(int j = 0; j < n; j++){
			if(i == 0){
				dp[(1 << j) | i][j].first.first = v[j]*20.0;
				dp[(1 << j) | i][j].first.second = 0;
				dp[(1 << j) | i][j].second = -1;
 			}
			else{
				if(i & (1 << j)) continue;
				for(int k = 0; k < n; k++){
					if(!(i & (1 << k))) continue;
					int pv = dp[i][k].first.first;
					int pd = dp[i][k].first.second;
					if((2000.0 / (70.0 + pv)) <= 0) continue;
					if(dp[i | (1 << j)][j].first.second > pd + (abs(d[j] - d[k]) / (2000.0 / (70.0 + pv)))){
						dp[i | (1 << j)][j].first.first = pv + v[j]*20.0;
						dp[i | (1 << j)][j].first.second = pd + (abs(d[j] - d[k]) / (2000.0 / (70.0 + pv)));
						dp[(1 << j) | i][j].second = k;
					}
				}
			}
		}
	}
	int st = -1;
	int ma = INF;
	for(int i = 0; i < n; i++){
		if(ma > dp[(1 << n) - 1][i].first.second){
			ma = dp[(1 << n) - 1][i].first.second;
			//cout << ma << endl;
			st = i;
		}
		//out << dp[(1 << n) - 1][i].first.second << endl;
	}
	dfs(st, (1 << n)-1);
	//cout << endl;
	for(int i = n-1; i >= 0; i--){
		if(i == 0) cout << e[i] << endl;
		else cout << e[i] << " ";
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 27752
final_rank: 18

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
ll MOD = 1000000007;

signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<ll> s(n), d(n), v(n);
  REP(i, n) cin >> s[i] >> d[i] >> v[i];

  vector<ll> weight(1<<n);
  REP(i, 1<<n) {
    REP(j, n) {
      if(i&1<<j) weight[i] += v[j] * 20;
    }
  }

  auto dp = make_v<double>(1<<n, n);
  fill_v(dp, LLINF);
  auto prev = make_v<ll>(1<<n, n);
  REP(i, n) {
    dp[1<<i][i] = 0;
    prev[1<<i][i] = -1;
  }
  REP(i, 1<<n) REP(j, n) {
    REP(k, n) {
      if(!(i&1<<k)) {
        double ndist = dp[i][j] + (70+weight[i]) / 2000.0 * abs(d[j]-d[k]);
        if(dp[i|1<<k][k] > ndist) {
          dp[i|1<<k][k] = ndist;
          prev[i|1<<k][k] = j;
        }
      }
    }
  }

  ll idx = -1;
  double mi = LLINF;
  REP(i, n) {
    if(mi > dp[(1<<n)-1][i]) {
      mi = dp[(1<<n)-1][i];
      idx = i;
    }
  }

  vector<ll> path;
  ll mask = (1<<n)-1, now = idx;
  while(now != -1) {
    path.push_back(now);
    ll tmp = now;
    now = prev[mask][now];
    mask ^= 1<<tmp;
  }
  reverse(ALL(path));

  REP(i, path.size()) {
    cout << s[path[i]];
    if(i != path.size()-1) cout << " ";
  }
  cout << endl;

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 12904
final_rank: 15

code_snippet: // 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, S[20], D[20], V[20];
double dp[1 << 15][15];
vector<int> vec[1 << 15][15];
 
signed main() {
    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> S[i] >> D[i] >> V[i];
    }

    fill(dp[0], dp[1<<N], INF);
    dp[0][0] = 0;

    for(int bit=0; bit<(1<<N); bit++) {
        for(int k=0; k<N; k++) {
            if(dp[bit][k] == INF) continue;

            int weight = 0;
            for(int i=0; i<N; i++) {
                if(bit >> i & 1) weight += V[i] * 20;
            }
            for(int i=0; i<N; i++) {
                if(bit >> i & 1) continue;
                else {
                    int nbit = bit | (1 << i);
                    int pre = (bit ? D[k] : 0);
                    int dist = abs(D[i] - pre);

                    double cost = dist / (2000.0 / (70 + weight));
                    if(dp[nbit][i] > dp[bit][k] + cost) {
                        dp[nbit][i] = dp[bit][k] + cost;
                        vec[nbit][i] = vec[bit][k];
                        vec[nbit][i].push_back(S[i]);
                    }
                }
            }
        }
    }
    
    vector<int> ans;
    double rec = INF;
    for(int i=0; i<N; i++) {
        if(rec > dp[(1<<N)-1][i]) {
            rec = dp[(1<<N)-1][i];
            ans = vec[(1<<N)-1][i];
        }
    }

    for(size_t i=0; i<ans.size(); i++) {
        cout << ans[i] << " \n"[i+1==ans.size()];
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 49072
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

double dp[1<<15][15],MIN=1e15;
int pre[1<<15][15],s[15],d[15],v[15],id,S,n;

main(){
	cin>>n;
	r(i,n)cin>>s[i]>>d[i]>>v[i];
	r(i,1<<n)r(j,15)dp[i][j]=1e15;
	r(i,n)dp[1<<i][i]=0;
	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(j==k)continue;
				if((i&(1<<k)))continue;
				double sum=0,dis=abs(d[k]-d[j]);
				r(l,n)if(i&(1<<l))sum+=v[l];
				double cost=dp[i][j];
				cost+=dis/(2000.0/(sum*20+70));
				if(dp[i|(1<<k)][k]>cost){
					dp[i|(1<<k)][k]=cost;
					pre[i|(1<<k)][k]=j;
				}
			}
		}
	}
	r(i,n)if(MIN>dp[(1<<n)-1][i]){
		MIN=dp[(1<<n)-1][i];
		id=i;
	}
	stack<int>st;
	S=(1<<n)-1;
	r(i,n){
		st.push(s[id]);
		S-=(1<<id);
		id=pre[S|(1<<id)][id];
	}
	r(i,n){
		if(i)cout<<' ';
		cout<<st.top();
		st.pop();
	}
	cout<<endl;
}
accuracy: 1
time_ms: 80
memory_kb: 8760
final_rank: 19

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int n;
int s[15],d[15],v[15];
double dp[1<<15][15];
int sum[1<<15];
int parent[1<<15][15];
void print(int k,int a)
{
	int l=k&~(1<<a);
	if(l)
	{
		print(l,parent[k][a]);
		cout<<" ";
	}
	cout<<s[a];
}
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>d[i]>>v[i];
		for(int j=0;j<1<<n;j++)dp[j][i]=1e300;
	}
	for(int i=0;i<1<<n;i++)
	{
		for(int j=0;j<n;j++)if(i&1<<j)sum[i]+=v[j];
	}
	for(int i=0;i<n;i++)dp[0][i]=0;
	for(int i=1;i<1<<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(!(i&1<<j))continue;
			int k=i&~(1<<j);
			double ans=dp[i][j];
			int p;
			for(int l=0;l<n;l++)
			{
				double now=dp[k][l]+(70+sum[k]*20)/2e3*abs(d[l]-d[j]);
				if(ans>now)
				{
					ans=now;
					p=l;
				}
			}
			dp[i][j]=ans;
			parent[i][j]=p;
		}
	}
	double m=1e300;int p,k=(1<<n)-1;
	for(int i=0;i<n;i++)if(m>dp[k][i])m=dp[k][i],p=i;
	print(k,p);
	cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 8888
final_rank: 3

code_snippet: #include <stdio.h>
#include <vector>
using namespace std;
#define PB push_back
const int N=1e1+10;
const int MAXN=1<<16;
const double INF=1<<30;
int abs(int a){return a>0?a:-a;}
int main(){
    int n,s[N],d[N],v[N],from[MAXN][N],val[MAXN],all,now=0,top;
    vector<int> ans;
    double dp[MAXN][N],temp;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d%d%d",&s[i],&d[i],&v[i]);
    all=1<<n;
    for(int i=0;i<all;i++){
        val[i]=0;
        for(int j=0;j<n;j++){
            dp[i][j]=INF;
            if(i&(1<<j))val[i]+=v[j];
        }
        val[i]*=20;
    }
    for(int i=0;i<n;i++){
        from[1<<i][i]=-1;
        dp[1<<i][i]=((double)70/2000)*d[i];
    }
    for(int i=0;i<all;i++)for(int j=0;j<n;j++)if(i&(1<<j)){
        for(int k=0;k<n;k++)if(k!=j&&i&(1<<k)){
            temp=dp[i^(1<<j)][k]+((double)(70+val[i^(1<<j)])/2000)*abs(d[j]-d[k]);
            if(dp[i][j]>temp){
                from[i][j]=k;
                dp[i][j]=temp;
            }
        }
    }
    all--;
    top=dp[all][0];
    for(int i=1;i<n;i++)if(dp[all][i]<top){
        top=dp[all][i];
        now=i;
    }
    while(all>0){
        ans.PB(s[now]);
        top=all;
        all-=1<<now;
        now=from[top][now];
    }
    printf("%d",ans.back());
    for(int i=static_cast<int>(ans.size()-2);i>=0;i--)printf(" %d",ans[i]);
    printf("\n");
}
accuracy: 1
time_ms: 20
memory_kb: 10400
final_rank: 11

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define mod 1000000007
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[1<<16][15];
pair<int,int> from[1<<16][15];
int w[1<<16],n;
int s[15],d[15],v[15];
int main(){
  cin>>n;
  lol(i,n){
    cin>>s[i]>>d[i]>>v[i];
    lol(j,(1<<n)){
      dp[j][i]=mod;
    }
    dp[(1<<i)][i]=0;
  }
  w[0]=0;
  for(int k=0;k<(1<<n);k++){
    lol(last,n){
      lol(to,n){
	if(k%(1<<(to+1))>=(1<<to))continue;
	int tmp=dp[k][last]+abs(d[to]-d[last])*(7+2*w[k]);
	if(tmp<dp[k+(1<<to)][to]){
	  dp[k+(1<<to)][to]=tmp;
	  from[k+(1<<to)][to]=make_pair(k,last);
	}
	w[k+(1<<to)]=w[k]+v[to];
      }
    }
  }
  vector<int> v;
  pair<int,int> pnt;
  int mini=mod;
  lol(i,n){
    if(mini>dp[(1<<n)-1][i]){
      mini=dp[(1<<n)-1][i];
      pnt=make_pair((1<<n)-1,i);
    }
  }
  while(true){
    int a=pnt.first,b=pnt.second;
    v.push_back(s[b]);
    if(a==(1<<b))break;
    pnt=from[a][b];
  }
  lol(i,v.size()){
    if(i)cout<<" ";
    cout<<v[v.size()-1-i];
  }
  cout<<endl;
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 12816
final_rank: 17