Submission #56767

# Submission time Handle Problem Language Result Execution time Memory
56767 2018-07-12T14:30:11 Z win11905 Teleporters (IOI08_teleporters) C++11
95 / 100
795 ms 66560 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
 
const int N = 2e6+5;
 
int n, m, psz, pz1;
bool Check[N];
 
int main() {
  	vector<int> V(N), val(N), neibour(N), Com(N);
    scanf("%d %d", &n, &m);
    for(int i = 0, u, v; i < n; ++i) {
        scanf("%d %d", &u, &v);
        neibour[u] = v, neibour[v] = u;
        V[u]++, V[v]++;
    }
    for(int i = 1; i < N; ++i) {
        V[i] += V[i-1];
        if(V[i] != V[i-1]) Com[pz1++] = i;
    }
    int cnt = 0, p = 0; Check[0] = true;
    while(p != (n<<1)) Check[p = V[neibour[Com[p]]]] = true, cnt++;
    for(int i = 1; i <= (n<<1); ++i) if(!Check[i]) {
        int u = i, sz = 0; Check[u] = true;
        do Check[u = V[neibour[Com[u]]]] = true, sz++; while(u != i);
        val[++psz] = sz;
    }
    sort(val.begin()+1, val.begin() + psz + 1, greater<int>()); for(int i = 1; i <= psz; ++i) val[i] += val[i-1]; 
    cnt += val[min(psz, m)] + 2 * min(psz, m);
    if(m > psz) m -= psz, cnt += ((m>>1)<<2) + (m & 1);
    printf("%d\n", cnt);
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:14: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:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 39 ms 31736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 31736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31940 KB Output is correct
2 Correct 35 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31940 KB Output is correct
2 Correct 43 ms 31980 KB Output is correct
3 Correct 37 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 32112 KB Output is correct
2 Correct 259 ms 32620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 32620 KB Output is correct
2 Correct 364 ms 32712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 408 ms 33132 KB Output is correct
2 Correct 480 ms 33388 KB Output is correct
3 Correct 482 ms 33516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 778 ms 33644 KB Output is correct
2 Correct 795 ms 44012 KB Output is correct
3 Correct 541 ms 44056 KB Output is correct
4 Correct 510 ms 44056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 623 ms 44056 KB Output is correct
2 Correct 644 ms 58796 KB Output is correct
3 Runtime error 327 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
4 Halted 0 ms 0 KB -