Submission #56474

#TimeUsernameProblemLanguageResultExecution timeMemory
56474aquablitz11Teleporters (IOI08_teleporters)C++14
85 / 100
885 ms66560 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int n, m; int A[N], B[N], pos[2*N], coord[2*N], nxt[2*N]; bool vis[2*N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d%d", &A[i], &B[i]); coord[2*i+1] = A[i]; coord[2*i+2] = B[i]; } sort(coord, coord+2*n+1); for (int i = 0; i < 2*n+1; ++i) pos[coord[i]] = i; for (int i = 0; i < n; ++i) { nxt[pos[A[i]]-1] = pos[B[i]]; nxt[pos[B[i]]-1] = pos[A[i]]; } vector<int> cycle; cycle.reserve(n); int ans = 0; for (int s = 0; s < 2*n; ++s) { if (vis[s]) continue; for (int u = s, c = 1; ; ++c) { vis[u] = true; u = nxt[u]; if (vis[u]) { cycle.push_back(c); break; } else if (u == 2*n) { ans = c; break; } } } sort(cycle.begin(), cycle.end()); while (m--) { if (!cycle.empty()) { ans += cycle.back()+2; cycle.pop_back(); } else { ++ans; cycle.push_back(1); } } printf("%d\n", ans); return 0; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
teleporters.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i], &B[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...