Submission #125876

#TimeUsernameProblemLanguageResultExecution timeMemory
125876SortingRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
113 ms19960 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int M = (1 << 16) + 7; const long long inf = 1e18 + 7; pair<long long, bool> dp[M][19]; int n; pair<int, int> p[N]; long long solve(int state, int pr = 17){ if(dp[state][pr].second){ return dp[state][pr].first; } if(state == (1 << n) - 1){ return 0; } dp[state][pr].second = true; dp[state][pr].first = inf; long long curr; if(pr == 17){ curr = 1; } else{ curr = p[pr].second; } for(int i = 0; i < n; i++){ if((1 << i) & state){ continue; } dp[state][pr].first = min(dp[state][pr].first, solve(state | (1 << i), i) + max(curr - p[i].first, 0ll)); } return dp[state][pr].first; } long long plan_roller_coaster(vector<int> s, vector<int> t){ n = (int)s.size(); for(int i = 0; i < n; i++){ p[i] = {s[i], t[i]}; } return solve(0); } /*int main(){ int nn; cin >> nn; vector<int> s, t; for(int i = 0; i < nn; i++){ int x, y; cin >> x >> y; s.push_back(x); t.push_back(y); } cout << plan_roller_coaster(s, t) << endl; return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...