Submission #569428

# Submission time Handle Problem Language Result Execution time Memory
569428 2022-05-27T11:43:56 Z 79brue Teleporters (IOI08_teleporters) C++17
0 / 100
865 ms 25832 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k, len;
int nxt[2000002];
bool visited[2000002];
int l[1000002], r[1000002];
vector<int> vec;
int base;

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%d %d", &l[i], &r[i]);
        vec.push_back(l[i]), vec.push_back(r[i]);
    }
    sort(vec.begin(), vec.end());
    len = n*2;
    for(int i=0; i<len; i++) nxt[i] = i+1;
    for(int i=1; i<=n; i++){
        l[i] = lower_bound(vec.begin(), vec.end(), l[i]) - vec.begin() + 1;
        r[i] = lower_bound(vec.begin(), vec.end(), r[i]) - vec.begin() + 1;
        nxt[l[i]-1] = r[i];
        nxt[r[i]-1] = l[i];
    }
    nxt[len] = 0;
    vec.clear();
    for(int i=0; i<=len; i++){
        if(visited[i]) continue;
        int x = i, cnt = 0;
        while(!visited[x]){
            visited[x] = 1;
            cnt++;
            x = nxt[x];
        }
        if(i==0) base = cnt;
        else vec.push_back(cnt);
    }
    sort(vec.begin(), vec.end());
    --base;
    while(k--){
        if(vec.empty()) base += 2;
        else exit(1), base += vec.back() + 2, vec.pop_back();
    }
    printf("%d", base);
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
teleporters.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d %d", &l[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 380 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 340 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 408 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 776 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 848 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 81 ms 3556 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 159 ms 5768 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 478 ms 16212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 731 ms 22724 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 865 ms 25832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -