Submission #851690

#TimeUsernameProblemLanguageResultExecution timeMemory
851690pomuchleRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
34 ms9304 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...