Submission #503835

#TimeUsernameProblemLanguageResultExecution timeMemory
503835tabrTeleporters (IOI08_teleporters)C++17
90 / 100
631 ms65540 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<pair<int, int>> a(n); vector<int> b(2 * n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; b[2 * i] = a[i].first; b[2 * i + 1] = a[i].second; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (int i = 0; i < n; i++) { a[i].first = (int) (lower_bound(b.begin(), b.end(), a[i].first) - b.begin()); a[i].second = (int) (lower_bound(b.begin(), b.end(), a[i].second) - b.begin()); } vector<int> c(2 * n); for (int i = 0; i < n; i++) { c[a[i].first] = a[i].second; c[a[i].second] = a[i].first; } vector<int> was(2 * n); vector<vector<int>> path; vector<int> d; for (int z = 0; z < 2 * n; z++) { if (was[z]) { continue; } int now = z; path.emplace_back(); do { was[now] = 1; path.back().emplace_back(now); now = c[now] + 1; } while (now < 2 * n && now != z); if (path.size() > 1) { d.emplace_back((int) path.back().size()); } } int ans = (int) path[0].size(); sort(d.rbegin(), d.rend()); debug(path); debug(d); int t = 0; for (int i = 0; i < m; i++) { if (i < (int) d.size()) { ans += d[i] + 2; } else if (t) { ans += 3; t ^= 1; } else { ans++; t ^= 1; } } cout << ans << '\n'; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...