Submission #98867

#TimeUsernameProblemLanguageResultExecution timeMemory
98867shoemakerjoTeleporters (IOI08_teleporters)C++14
100 / 100
794 ms45160 KiB
#include <bits/stdc++.h> using namespace std; int N, M; const int maxn = 2000010; int aft[maxn]; int bef[maxn]; bool isin[maxn]; bool vis[maxn]; int a[maxn], b[maxn]; int previn[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fill(aft, aft+maxn, -1); cin >> N >> M; for (int i = 0; i < N; i++) { cin >> a[i] >> b[i]; isin[a[i]] = true; isin[b[i]] = true; } int cp = 0; for (int i = 1; i < maxn; i++) { if (isin[i]) { previn[i] = cp; cp = i; } } for (int i = 0; i < N; i++) { aft[previn[a[i]]] = b[i]; bef[b[i]] = previn[a[i]]; // cout << "thing: " << previn[a[i]] << " - " << b[i] << // " :: " << a[i] << endl; aft[previn[b[i]]] = a[i]; bef[a[i]] = previn[b[i]]; } isin[0] = true; vector<int> cyclen; int clen = 0; for (int i = 0; i < maxn; i++) { if (!isin[i] || vis[i]) continue; int cv = 0; int u = i; bool ip = false; // cout << " path: "; while (!vis[u]) { // cout << u << " "; cv++; vis[u] = true; u = aft[u]; if (u == -1) { ip = true; clen = cv-1; break; } } // cout << u << endl; if (!ip) cyclen.push_back(cv); } sort(cyclen.begin(), cyclen.end()); reverse(cyclen.begin(), cyclen.end()); // cout << "this: " << clen << endl; for (int i = 0; i < cyclen.size(); i++) { if (M == 0) break; M--; clen += cyclen[i] + 2; } if (M) { int d2 = M/2; if (M %2 == 1) clen++; clen += d2 * 4; } cout << clen << endl; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:79:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < cyclen.size(); 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...