Submission #958831

#TimeUsernameProblemLanguageResultExecution timeMemory
958831MinaRagy06Roller Coaster Railroad (IOI16_railroad)C++17
0 / 100
2036 ms17808 KiB
#include <bits/stdc++.h> #include "railroad.h" #ifdef MINA #include "grader.cpp" #endif using namespace std; #define ll long long ll plan_roller_coaster(vector<int> in, vector<int> out) { int n = in.size(); set<array<int, 2>> s; for (int i = 0; i < n; i++) { s.insert({in[i], out[i]}); } vector<array<int, 2>> a; while (s.size()) { array<int, 2> val = *s.begin(); s.erase(s.begin()); int st = val[0]; while (1) { auto it = s.lower_bound({val[1], 0}); if (it == s.end()) { break; } val = *it; s.erase(it); } int en = val[1]; a.push_back({st, en}); } n = a.size(); ll sum = 0; for (int i = 0; i < n; i++) { sum += a[i][1] - a[i][0]; } if (n == 1) { return 0; } ll ans = 1e18; for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { if (x == y) continue; ans = min(ans, sum + a[x][0] - a[y][1]); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...