# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140457 | bazsi700 | Roller Coaster Railroad (IOI16_railroad) | C++14 | 221 ms | 156712 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.
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
#define hashA 1257958787
#define hashB 1539500609
#define endl "\n"
ll dp[17][17][66000];
ll plan_roller_coaster(vector<int> s, vector<int> t) {
int n = s.size();
for(int i = 0; i < 17; i++) {
for(int k = 0; k < 17; k++) {
for(int j = 0; j < 66000; j++) {
dp[i][k][j] = INF;
}
}
}
if(n <= 16) {
for(int i = 0; i < n; i++) {
dp[1][i][(1<<i)] = 0;
}
for(int i = 2; i <= n; i++) {
for(int lst = 0; lst < n; lst++) {
for(int mask = 0; mask < (1<<n); mask++) {
if((mask&(1<<lst)) == 0) {
continue;
}
vector<int> setbits;
for(int k = 0; k < n; k++) {
if(mask&(1<<k)) {
setbits.push_back(k);
}
}
if(setbits.size() != i) {
continue;
}
for(int k : setbits) {
int oldmask = mask^(1<<k);
for(int l : setbits) {
if(l != k && l != lst) {
dp[i][lst][mask] = min(dp[i][lst][mask],dp[i-1][l][oldmask]+max(0,t[l]-s[lst]));
}
}
}
}
}
}
ll ans = INF;
for(int lst = 0; lst < n; lst++) {
ans = min(ans,dp[n][lst][(1<<n)-1]);
}
return ans;
}
return 0;
}
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... |