# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069672 | mc061 | Roller Coaster Railroad (IOI16_railroad) | C++14 | 37 ms | 15184 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma once
#include <bits/stdc++.h>
using namespace std;
const int N = 16;
int64_t ham_path[1<<N][N];
int64_t dist[N][N];
long long plan_roller_coaster(vector<int> s, vector<int> t) {
const int n = s.size();
for (int i = 0; i < (1<<n); ++i) {
fill(ham_path[i], ham_path[i]+n, 1e18);
}
ham_path[0][0] = 0;
for (int i = 0; i < n; ++i) {
ham_path[1<<i][i] = 0;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i==j) {
dist[i][j]=1e18;
continue;
}
dist[i][j] = max(0, t[i]-s[j]);
}
}
for (int m = 1; m < (1<<n); ++m) {
vector<int> bits;
for (int bit = 0; bit < n; ++bit) {
if ((m & (1 << bit)) == 0) continue;
bits.push_back(bit);
}
if (bits.size() == 1) {
continue;
}
for (int i = 0; i < bits.size(); ++i) {
int prev_m = m ^ (1 << bits[i]);
assert(prev_m < m);
for (int j = 0; j < bits.size(); ++j) {
if (i == j) continue;
ham_path[m][bits[i]] = min(ham_path[m][bits[i]], ham_path[prev_m][bits[j]] + dist[bits[j]][bits[i]]);
}
}
}
return *min_element(ham_path[(1<<n)-1], ham_path[(1<<n)-1]+n);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |