제출 #1029650

#제출 시각아이디문제언어결과실행 시간메모리
1029650thinknoexitTeleporters (IOI08_teleporters)C++17
100 / 100
202 ms36812 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1001000; bool ch[2 * N]; int w[2 * N], c[2 * N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0;i <= 2000000;i++) w[i] = i + 1; for (int i = 1, l, r;i <= n;i++) { cin >> l >> r; w[l] = r + 1, c[l] = 1; w[r] = l + 1, c[r] = 1; } int ans = 0; vector<int> v; w[2000000] = 0; for (int i = 0;i <= 2000000;i++) { if (!ch[i]) { int now = i; int res = 0; while (!ch[now]) { ch[now] = 1; res += c[now]; now = w[now]; } if (i != 0) v.push_back(res); else ans += res; } } sort(v.rbegin(), v.rend()); for (int i = 0;i < min(m, (int)v.size());i++) ans += v[i] + 2; m -= min(m, (int)v.size()); if (m & 1) ans += 2 * m - 1; else ans += 2 * m; 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...