# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56492 | aquablitz11 | Teleporters (IOI08_teleporters) | C++14 | 752 ms | 43060 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 <stdio.h>
#include <stdlib.h>
#define N 1000001
int n, m;
int A[N], B[N], pos[2*N], coord[2*N], cc;
int comp(const void *a, const void *b) {
return *(int*)a - *(int*)b;
}
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];
}
qsort(coord, 2*n+1, sizeof(int), comp);
for (int i = 0; i < 2*n+1; ++i)
pos[coord[i]] = i;
for (int i = 0; i < n; ++i) {
A[i] = pos[A[i]];
B[i] = pos[B[i]];
}
for (int i = 0; i < n; ++i) {
pos[A[i]-1] = B[i];
pos[B[i]-1] = A[i];
}
for (int i = 0; i < 2*n+1; ++i)
coord[i] = 0;
int ans = 0;
for (int s = 0; s < 2*n; ++s) {
if (coord[s]) continue;
for (int u = s, c = 1; ; ++c) {
coord[u] = 1;
u = pos[u];
if (coord[u]) {
A[cc++] = c;
break;
} else if (u == 2*n) {
ans = c;
break;
}
}
}
qsort(A, cc, sizeof(int), comp);
while (m--) {
if (cc > 0) {
ans += A[--cc]+2;
} else {
++ans;
A[cc++] = 1;
}
}
printf("%d\n", ans);
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... |