# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58266 | 2018-07-17T10:25:57 Z | memikakizaki | Teleporters (IOI08_teleporters) | C++14 | 765 ms | 66560 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1e6+3, INF = 1e9; int n, m, lf[N], rg[N], vals[2*N], rev[2*N], nxt[2*N]; vector<int> cycles; bitset<N<<1> mark; long ans; int main() { scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) { scanf("%d %d", &lf[i], &rg[i]); vals[i<<1] = lf[i]; vals[i<<1|1] = rg[i]; } vals[2*n] = -1; sort(vals, vals+2*n+1); for(int i = 0; i <= n << 1; i++) rev[vals[i]] = i; for(int i = 0; i < n; i++) { nxt[rev[lf[i]]-1] = rev[rg[i]]; nxt[rev[rg[i]]-1] = rev[lf[i]]; } nxt[2*n] = INF; cycles.reserve(n); for(int i = 0; i <= n << 1; i++) if(!mark[i]) { int curr = i, sz = 0; bool cycle = false; while(curr != INF) { if(mark[curr]) { cycle = true; break; } ++sz; mark[curr] = true; curr = nxt[curr]; } if(cycle) cycles.push_back(sz); else ans = sz-1; } sort(cycles.begin(), cycles.end(), greater<int>()); for(int i = 0; i < min((int) cycles.size(), m); i++) ans += cycles[i] + 2; if(m > cycles.size()) { m -= cycles.size(); ans += (m - (m & 1)) << 1 + (m & 1); } printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 564 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 564 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 564 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 720 KB | Output is correct |
2 | Correct | 7 ms | 984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 984 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 5696 KB | Output is correct |
2 | Correct | 211 ms | 14648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 139 ms | 14648 KB | Output is correct |
2 | Incorrect | 299 ms | 19532 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 428 ms | 24932 KB | Output is correct |
2 | Correct | 491 ms | 35496 KB | Output is correct |
3 | Correct | 483 ms | 37064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 732 ms | 37940 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 692 ms | 41872 KB | Output is correct |
2 | Correct | 765 ms | 42192 KB | Output is correct |
3 | Correct | 585 ms | 57912 KB | Output is correct |
4 | Runtime error | 725 ms | 66560 KB | Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |