제출 #757302

#제출 시각아이디문제언어결과실행 시간메모리
757302SanguineChameleonTeleporters (IOI08_teleporters)C++17
85 / 100
404 ms64812 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } const int maxn = 1e6 + 20; pair<int, int> a[maxn * 2]; int adj[maxn * 2]; bool flag[maxn]; int sz = 0; void dfs(int u) { flag[u] = true; sz++; if (!flag[adj[u]]) { dfs(adj[u]); } } void just_do_it() { int n, m; cin >> n >> m; n++; a[1] = make_pair(0, 1); a[2] = make_pair(maxn * 2, n + 1); for (int i = 2; i <= n; i++) { a[i * 2 - 1].second = i; a[i * 2].second = n + i; cin >> a[i * 2 - 1].first >> a[i * 2].first; } sort(a + 1, a + n * 2 + 1); for (int i = 1; i <= n * 2 - 1; i++) { int u = a[i].second; int v = a[i + 1].second; if (v > n) { v -= n; } else { v += n; } adj[u] = v; } dfs(1); int res = sz - 1; vector<int> sizes; for (int i = 1; i <= n * 2; i++) { if (i != n + 1 && !flag[i]) { sz = 0; dfs(i); sizes.push_back(sz); } } sort(sizes.begin(), sizes.end(), greater<int>()); for (int i = 0; i < (int)sizes.size() && m > 0; i++) { res += sizes[i] + 2; m--; } res += 4 * (m / 2) + (m % 2); cout << res; }
#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...