# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
799670 | Khizri | Roller Coaster Railroad (IOI16_railroad) | C++17 | 37 ms | 10544 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 "railroad.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=20;
ll n,dp[(1<<mxn)][mxn];
long long plan_roller_coaster(vector<int> s, vector<int> t) {
n = (int) s.size();
for(int mask=1;mask<(1<<n);mask++){
ll mn=INF;
if(__builtin_popcount(mask)==1){
for(int i=0;i<n;i++){
if(mask&(1<<i)){
dp[mask][i]=0;
}
}
continue;
}
for(int i=0;i<n;i++){
if(!(mask&(1<<i))) continue;
dp[mask][i]=INF;
for(int j=0;j<n;j++){
if(!((mask^(1<<i))&(1<<j))) continue;
dp[mask][i]=min(dp[mask][i],dp[mask^(1<<i)][j]+max(0,t[j]-s[i]));
}
}
}
ll ans=INF;
for(int i=0;i<n;i++){
ans=min(ans,dp[(1<<n)-1][i]);
}
return ans;
}
/*
g++ railroad.cpp grader.cpp ; .\a.exe
4
1 7
4 3
5 8
6 6
*/
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... |