Submission #218281

#TimeUsernameProblemLanguageResultExecution timeMemory
218281tatyamTeleporters (IOI08_teleporters)C++17
100 / 100
975 ms54248 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define rep(a) for(int i = 0; i < a; i++) #define each(i,a) for(auto&& i : a) #define all(a) begin(a), end(a) int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<pii> a(n); vector<int> x; each(i, a){ int a, b; cin >> a >> b; i = {a, b}; x.push_back(a); x.push_back(b); } sort(all(x)); x.erase(unique(all(x)), x.end()); vector<int> to(n * 2); each(i, a){ i.first = lower_bound(all(x), i.first) - x.begin(); i.second = lower_bound(all(x), i.second) - x.begin(); to[i.first] = i.second; to[i.second] = i.first; } vector<int> color(n * 2, -1), cnt; int at = 0, c = 0, ans = 0; while(at != n * 2){ color[at] = c; ans++; at = to[at] + 1; } rep(n * 2) if(color[i] == -1){ cnt.push_back(0); int at = i; c++; while(at != n * 2 && color[at] == -1){ color[at] = c; cnt.back()++; at = to[at] + 1; } } sort(all(cnt)); while(cnt.size() && m){ ans += cnt.back() + 2; cnt.pop_back(); m--; } ans += m / 2 * 4 + m % 2; cout << ans << endl; }
#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...