Submission #56771

# Submission time Handle Problem Language Result Execution time Memory
56771 2018-07-12T14:35:41 Z win11905 Palindromic Partitions (CEOI17_palindromic) C++11
0 / 100
10000 ms 31608 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

palindromic.cpp: In function 'int main()':
palindromic.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);
     ~~~~~^~~~~~~~~~~~~~~~~
palindromic.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 Execution timed out 10029 ms 31608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10029 ms 31608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10029 ms 31608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10029 ms 31608 KB Time limit exceeded
2 Halted 0 ms 0 KB -