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 pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b;i<ioi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) {for(auto dkfjhg:v)cout<<dkfjhg<<" ";cout<<"\n";}
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=2e5+5,INF=1e15;
long long plan_roller_coaster(std::vector<int> A, std::vector<int> B) {
vector<ll>a,b;
for(auto i:A)a.pb(i);
for(auto i:B)b.pb(i);
ll n=SZ(a);
auto bin=[&](ll mk){
string r;
fore(i,0,n)r.pb('0'+(mk>>i&1));
return r;
};
vector<vector<ll>>dp(1ll<<n,vector<ll>(n));
fore(mk,1,1ll<<n)fore(x,0,n){
ll &res=dp[mk][x];
res=INF;
// if(!mk){res=0;continue;}
fore(y,0,n)if(mk>>y&1){
res=min(res,max(b[x]-a[y],0ll)+dp[mk^(1ll<<y)][y]);
}
// cout<<bin(mk)<<" "<<x<<": "<<res<<"\n\n";
}
ll res=INF,u=(1ll<<n)-1;
fore(i,0,n)res=min(res,dp[u^(1ll<<i)][i]);
return res;
}
Compilation message (stderr)
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:21:7: warning: variable 'bin' set but not used [-Wunused-but-set-variable]
21 | auto bin=[&](ll mk){
| ^~~
# | 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... |