Submission #583260

#TimeUsernameProblemLanguageResultExecution timeMemory
583260JomnoiTeleporters (IOI08_teleporters)C++17
20 / 100
223 ms34388 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 5; int W[MAX_N], E[MAX_N]; int id[MAX_N]; int parent[MAX_N], sz[MAX_N]; int find_parent(int u) { if(u == parent[u]) { return u; } return parent[u] = find_parent(parent[u]); } void merge(int u, int v) { u = find_parent(u), v = find_parent(v); if(u == v) { return; } sz[u] += sz[v]; parent[v] = u; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; for(int i = 1; i <= N; i++) { cin >> W[i] >> E[i]; } sort(id + 1, id + N + 1, [&](const int &a, const int &b) { return W[a] < W[b]; }); iota(parent + 1, parent + N + 1, 1); fill(sz + 1, sz + N + 1, 1); for(int l = 1, r = 2; l <= N; l++) { while(r <= N and W[id[r]] <= E[id[l]]) { merge(id[l], id[r]); r++; } } int ans = 0; for(int i = 1; i <= N; i++) { if(find_parent(i) == i) { if(sz[i] > 1) { ans += 4; } else if(M > 0) { M--; ans += 4; } else { ans++; } } } while(M >= 2) { ans += 4; M -= 2; } ans += M; cout << ans; 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...