# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
772546 | kingfran1907 | Teleporters (IOI08_teleporters) | C++14 | 879 ms | 64052 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 25e5+10;
const int inf = 0x3f3f3f3f;
int n, m;
int l[maxn], r[maxn];
vector< int > v;
vector< pair<int, int> > vs;
int nex[maxn];
bool bio[maxn];
priority_queue< int > cycles;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d%d", l+i, r+i);
l[n] = -1;
r[n] = inf;
n++;
for (int i = 0; i < n; i++) {
v.push_back(l[i]);
v.push_back(r[i]);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
l[i] = lower_bound(v.begin(), v.end(), l[i]) - v.begin();
r[i] = lower_bound(v.begin(), v.end(), r[i]) - v.begin();
vs.push_back({l[i], i});
vs.push_back({r[i], i});
}
sort(vs.begin(), vs.end());
for (int i = 0; i < v.size() - 1; i++) {
int ind = vs[i + 1].second;
int rs = l[ind] + r[ind] - vs[i + 1].first;
nex[i] = rs;
}
int sol = 0;
for (int i = 0; i < v.size() - 1; i++) {
//printf("trying: %d\n", i);
if (bio[i]) continue;
int cnt = 0;
int ptr = i;
//printf("cycle: ");
while (!bio[ptr]) {
//printf("%d ", ptr);
bio[ptr] = true;
ptr = nex[ptr];
cnt++;
}
//printf("\n");
if (i > 0) cycles.push(cnt);
else sol = cnt - 1;
}
while (m && !cycles.empty()) {
//printf("debug: %d\n", cycles.top());
sol += cycles.top() + 2;
cycles.pop();
m--;
}
//printf("%d - %d\n", m, cycles.size());
m = m -= min(m, (int)cycles.size());
sol += 2 * (m - m % 2) + m % 2;
printf("%d\n", sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |