Submission #797448

#TimeUsernameProblemLanguageResultExecution timeMemory
797448QwertyPiRoller Coaster Railroad (IOI16_railroad)C++14
0 / 100
68 ms12068 KiB
#include "railroad.h" #include <bits/stdc++.h> #define fi first #define se second using namespace std; long long dp[200011]; int f(int a, int b){ return max(0, a - b); } long long plan_roller_coaster(vector<int> s, vector<int> t) { int n = (int) s.size(); vector<pair<int, int>> S, T; for(int i = 0; i < n; i++){ S.push_back({s[i], i}); } for(int i = 0; i < n; i++){ T.push_back({t[i], i}); } sort(S.begin(), S.end()); sort(T.begin(), T.end()); fill(dp + 1, dp + n + 1, 1LL << 60); for(int i = 0; i < n; i++){ if(S[i].se != T[i].se) dp[i + 1] = min(dp[i + 1], dp[i] + f(S[i].fi, T[i].fi)); if(i > 0 && S[i].se != T[i - 1].se && S[i - 1].se != T[i].se) dp[i + 1] = min(dp[i + 1], dp[i - 1] + f(S[i].fi, T[i - 1].fi) + f(S[i - 1].fi, T[i].fi)); } return dp[n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...