# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58257 | 2018-07-17T09:53:35 Z | memikakizaki | Teleporters (IOI08_teleporters) | C++14 | 1000 ms | 59188 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1e6+1, INF = 1e9; int n, m, lf[N], rg[N], nxt[N]; vector<int> vals, cycles; bitset<N> mark; long ans; int main() { scanf("%d %d", &n, &m); vals.reserve(2*n+1); for(int i = 0; i < n; i++) { scanf("%d %d", &lf[i], &rg[i]); vals.push_back(lf[i]); vals.push_back(rg[i]); } vals.push_back(INF); stable_sort(vals.begin(), vals.end()); for(int i = 0; i < n; i++) { lf[i] = lower_bound(vals.begin(), vals.end(), lf[i]) - vals.begin(); rg[i] = lower_bound(vals.begin(), vals.end(), rg[i]) - vals.begin(); nxt[lf[i]] = rg[i]+1; nxt[rg[i]] = lf[i]+1; } nxt[vals.size()-1] = INF; for(int i = 0; i < vals.size(); 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 | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 532 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 612 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 616 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 624 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 764 KB | Output is correct |
2 | Correct | 12 ms | 1052 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 1064 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 1364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 1640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 130 ms | 6344 KB | Output is correct |
2 | Correct | 312 ms | 15188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 15968 KB | Output is correct |
2 | Incorrect | 551 ms | 28300 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 742 ms | 53360 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1053 ms | 57564 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1067 ms | 59188 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |