Submission #583271

#TimeUsernameProblemLanguageResultExecution timeMemory
583271JomnoiTeleporters (IOI08_teleporters)C++17
100 / 100
359 ms44532 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 5; const int L = 2e6 + 1; int W[MAX_N], E[MAX_N]; pair <int, int> nxt[L + 1]; bool visited[L + 1]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; for(int i = 0; i < L; i++) { nxt[i] = make_pair(i + 1, 0); } for(int i = 1; i <= N; i++) { cin >> W[i] >> E[i]; nxt[W[i]] = make_pair(E[i] + 1, 1); nxt[E[i]] = make_pair(W[i] + 1, 1); } priority_queue <int> pq; visited[L] = true; int ans = 0; for(int i = 0; i <= L; i++) { if(visited[i] == true) { continue; } int u = i, cnt = 0; while(visited[u] == false) { visited[u] = true; cnt += nxt[u].second; u = nxt[u].first; } if(i == 0) { ans = cnt; } else { pq.push(cnt); } } while(M--) { if(!pq.empty()) { ans += pq.top() + 2; pq.pop(); } else { pq.push(1); ans++; } } 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...