Submission #595060

#TimeUsernameProblemLanguageResultExecution timeMemory
595060LucppRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
260 ms15964 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; ll plan_roller_coaster(vector<int> s, vector<int> t) { int n = (int)s.size(); if(n <= 16){ vector<vector<ll>> dp(1<<n, vector<ll>(n)); for(int msk=1; msk < (1<<n); msk++){ if(__builtin_popcount(msk) == 1) continue; for(int i = 0; i < n; i++){ if(!(msk & (1<<i))) continue; dp[msk][i] = INF; int m = msk^(1<<i); for(int j = 0; j < n; j++){ if(!(m & (1<<j))) continue; dp[msk][i] = min(dp[msk][i], dp[m][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; } else{ set<pair<int, int>> byS; for(int i = 0; i < n; i++) byS.emplace(s[i], t[i]); byS.emplace(int(1e9+1), 0); int a = s[0], b = t[0]; while(true){ byS.erase(make_pair(a, b)); if(byS.empty()) return b>s[0]; auto it = byS.lower_bound(make_pair(b, 0)); if(it == byS.end()) return 1; tie(a, b) = *it; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...