# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069663 | mc061 | Roller Coaster Railroad (IOI16_railroad) | C++17 | 352 ms | 524288 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;
long long plan_roller_coaster(vector<int> s, vector<int> t) {
const int n = s.size();
int64_t ham_path[1<<n][n];
for (int i = 0; i < (1<<n); ++i) {
fill(ham_path[i], ham_path[i]+n, 1e18);
}
int64_t dist[n][n];
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] = min<int64_t>(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]);
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... |