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"
#ifdef DEBUG
#include <cstdio>
#include <cassert>
int main() {
int n;
assert(1 == scanf("%d", &n));
std::vector<int> s(n), t(n);
for (int i = 0; i < n; ++i)
assert(2 == scanf("%d%d", &s[i], &t[i]));
long long ans = plan_roller_coaster(s, t);
printf("%lld\n", ans);
return 0;
}
#endif
#include <ios>
#include <vector>
#include <functional>
#include <set>
#include <cassert>
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, p, n) for(int i=(p); i<=(n); ++i)
#define V std::vector
#define sz(A) (int(A.size()))
typedef long long ll;
typedef V <int> vi;
typedef V <ll> vll;
typedef V <bool> vb;
const ll INF=1e18;
void M(ll &i, ll j){
i=std::min(i, j);
}
ll plan_roller_coaster(vi s, vi t) {
int n = sz(s);
assert(n<=16);
vb czy(n, 0);
struct ziom{
int o,w,i;
ziom(){}
ziom(int no, int nw, int ni){o=no,w=nw,i=ni;}
ziom(int j){o=w=i=j;}
};
V <ziom> z(n);
REP(i, n)
z[i]={s[i], t[i], i};
int fm=1<<n;
V <vll> dp(n, vll(fm, INF));
REP(i, n)
dp[i][1<<i]=0;
REP(m, fm)
REP(i, n){
if (!(m&(1<<i)))
continue;
REP(j, n){
int nm=m|(1<<j);
if (nm>m)
M(dp[j][nm], dp[i][m]+std::max(0, z[i].w-z[j].o));
}
}
ll w=INF;
REP(i, n)
M(w, dp[i][fm-1]);
return w;
}
# | 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... |