# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72607 | aleksam | Roller Coaster Railroad (IOI16_railroad) | C++14 | 117 ms | 17924 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>
#define MAX_N 16
#define INF 987654321987654321
using namespace std;
int N;
long long D[1<<MAX_N][MAX_N];
vector<long long> s, t;
void init(){
for(int i=0; i<N; ++i){
for(int j=0; j<(1<<N); ++j){
D[j][i]=-1;
}
}
for(int i=0; i<N; ++i){
D[1<<i][i]=0;
}
}
long long relu(long long v){
return v>0?v:0;
}
long long dp(int mask, int v){
//printf("mask=%d v=%d\n", mask, v);
if(D[mask][v]!=-1LL)return D[mask][v];
assert(mask&& (1<<v));
long long mini=INF;
for(int i=0; i<N; ++i){
if(((mask&(1<<i))!=0) && (i!=v)){
if(dp(mask^(1<<v), i)+relu(t[v]-s[i])<mini){
mini=dp(mask^(1<<v), i)+relu(t[v]-s[i]);
//printf("Pri (%d), mini=%lld\n", i, mini);
}
}
}
//printf("RET\n");
D[mask][v]=mini;
//printf("D[%d][%d]=%lld\n", mask, v, D[mask][v]);
return D[mask][v];
}
long long plan_roller_coaster(vector<int> S, vector<int> T) {
N=S.size();
for(int i=0; i<N; ++i){
s.push_back((long long)S[i]);
t.push_back((long long)T[i]);
}
init();
long long mini=INF;
for(int i=0; i<N; ++i){
if(dp((1<<N)-1, i)<mini){
mini=dp((1<<N)-1, i);
}
}
return mini;
}
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... |