Submission #56479

# Submission time Handle Problem Language Result Execution time Memory
56479 2018-07-11T12:49:14 Z aquablitz11 Teleporters (IOI08_teleporters) C++14
90 / 100
789 ms 66560 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000002;

int n, m;
int A[N], B[N], pos[2*N], coord[2*N], nxt[2*N], cc;
bool vis[2*N];

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];
    }
    sort(coord, coord+2*n+1);
    for (int i = 0; i < 2*n+1; ++i)
        pos[coord[i]] = i;
    for (int i = 0; i < n; ++i) {
        nxt[pos[A[i]]-1] = pos[B[i]];
        nxt[pos[B[i]]-1] = pos[A[i]];
    }

    int ans = 0;
    for (int s = 0; s < 2*n; ++s) {
        if (vis[s]) continue;
        for (int u = s, c = 1; ; ++c) {
            vis[u] = true;
            u = nxt[u];
            if (vis[u]) {
                A[cc++] = c;
                break;
            } else if (u == 2*n) {
                ans = c;
                break;
            }
        }
    }
    sort(A, A+cc);
    while (m--) {
        if (cc > 0) {
            ans += A[--cc]+2;
        } else {
            ++ans;
            A[cc++] = 1;
        }
    }
    printf("%d\n", ans);

    return 0;
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
teleporters.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i], &B[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 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 400 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 Correct 3 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 744 KB Output is correct
2 Correct 7 ms 1208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1208 KB Output is correct
2 Correct 10 ms 1708 KB Output is correct
3 Correct 16 ms 2280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 8388 KB Output is correct
2 Correct 207 ms 21644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 21644 KB Output is correct
2 Correct 324 ms 30140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 34704 KB Output is correct
2 Correct 575 ms 38004 KB Output is correct
3 Correct 619 ms 50024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 656 ms 52928 KB Output is correct
2 Runtime error 723 ms 66560 KB Memory limit exceeded 66560 {'time-wall': '0.802', 'max-rss': '33576', 'csw-forced': '174', 'cg-mem': '66560', 'time': '0.723', 'csw-voluntary': '9'} 65536
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 789 ms 66560 KB Memory limit exceeded 66560 {'time-wall': '0.829', 'max-rss': '34832', 'csw-forced': '44', 'cg-mem': '66560', 'time': '0.789', 'csw-voluntary': '3'} 65536
2 Halted 0 ms 0 KB -