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>
#define int long long
#define P(a) do{if(debug) cout<<a<<endl;} while(false)
#define H(a) P(#a<<": "<<a)
#define FR(i,a,b) for(int i = (a); i<(b); i++)
#define F(i,n) FR(i,0,n)
const int debug = 1;
const int inf = 1e18;
using namespace std;
bool f(int a, int b){
return (a&(1<<b)) != 0;
}
int n;
int dp[(1<<17)][17];
long long plan_roller_coaster(vector<signed> s, vector<signed> t) {
n = (int) s.size();
FR(i,1,1<<n) F(j, n) if(f(i,j)){
dp[i][j] = inf;
bool bol = true;
F(k,n) if(k!=j && f(i,k)){
bol = false;
dp[i][j] = min(dp[i][j], dp[i-(1<<j)][k] + max(0, t[k] - s[j]));
}
if(bol){
dp[i][j] = 0;
}
/*F(k,n){
cout<<f(i,k);
}
cout<<" "<<j<<": "<<dp[i][j]<<endl;*/
}
int ans = inf;
F(i,n){
ans = min(ans, dp[(1<<n)-1][i]);
}
return ans;
}
# | 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... |