Submission #583263

#TimeUsernameProblemLanguageResultExecution timeMemory
583263JomnoiTeleporters (IOI08_teleporters)C++17
25 / 100
333 ms19784 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]; } for(int i = 1; i <= N; i++) { id[i] = i; parent[i] = i; sz[i] = 1; } sort(id + 1, id + N + 1, [&](const int &a, const int &b) { return W[a] < W[b]; }); for(int l = 1, r = 2; l <= N; l++) { while(r <= N and W[id[r]] <= E[id[l]] and E[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...