Submission #96268

# Submission time Handle Problem Language Result Execution time Memory
96268 2019-02-07T16:54:16 Z popovicirobert ICC (CEOI16_icc) C++14
100 / 100
139 ms 632 KB
#include <bits/stdc++.h>
#include "icc.h"

using namespace std;

struct DSU {
    vector <int> par;
    stack <int> stk;
    int n;
    inline void init(int _n) {
        n = _n;
        par.resize(n + 1);
    }
    int root(int x) {
        if(par[x] == 0)
            return x;
        return par[x] = root(par[x]);
    }
    inline void join(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            stk.push(x);
            par[x] = y;
        }
        else {
            stk.push(-1);
        }
    }
    inline void undo() {
        if(stk.top() != -1) {
            par[stk.top()] = 0;
        }
        stk.pop();
    }
};

const int MAXN = 100;

int A[MAXN + 1], B[MAXN + 1];
int a[MAXN + 1], b[MAXN + 1];

inline void add(int *arr, int &sz, vector <int> &cur) {
    for(auto it : cur) {
        arr[sz++] = it;
    }
}

void run(int n) {
    int i;
    DSU dsu;
    dsu.init(n);
    for(int tt = 1; tt < n; tt++) {

        vector < vector <int> > comp(n + 1);
        vector <int> vis(n + 1, 0);
        int sz = 0;
        for(i = 1; i <= n; i++) {
            int x = dsu.root(i);
            if(!vis[x]) {
                vis[x] = ++sz;
            }
            comp[vis[x] - 1].push_back(i);
        }

        pair <int, int> edge;
        int bit;
        int sza, szb;
        for(bit = 0; (1 << bit) < sz; bit++) {
            sza = szb = 0;
            for(i = 0; i < sz; i++) {
                if(i & (1 << bit)) {
                    add(a, sza, comp[i]);
                }
                else {
                    add(b, szb, comp[i]);
                }
            }
            if((1 << (bit + 1)) >= sz) {
                break;
            }
            if(query(sza, szb, a, b)) {
                break;
            }
        }

        int szA = 0;
        for(int step = 1 << 6; step; step >>= 1) {
            if(szA + step < sza) {
                for(i = 0; i < szA + step; i++) {
                    A[i] = a[i];
                }
                if(!query(szA + step, szb, A, b))  {
                    szA += step;
                }
            }
        }
        edge.first = a[szA];

        int szB = 0;
        for(int step = 1 << 6; step; step >>= 1) {
            if(szB + step < szb) {
                for(i = 0; i < szB + step; i++) {
                    B[i] = b[i];
                }
                if(!query(sza, szB + step, a, B))  {
                    szB += step;
                }
            }
        }

        edge.second = b[szB];

        //cerr << edge.first << " " << edge.second << "\n";

        dsu.join(edge.first, edge.second);
        setRoad(edge.first, edge.second);
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:92:26: warning: 'szb' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 if(!query(szA + step, szb, A, b))  {
                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
icc.cpp:105:26: warning: 'sza' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 if(!query(sza, szB + step, a, B))  {
                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 504 KB Ok! 91 queries used.
2 Correct 7 ms 504 KB Ok! 95 queries used.
# Verdict Execution time Memory Grader output
1 Correct 34 ms 504 KB Ok! 544 queries used.
2 Correct 40 ms 504 KB Ok! 598 queries used.
3 Correct 38 ms 504 KB Ok! 605 queries used.
# Verdict Execution time Memory Grader output
1 Correct 113 ms 504 KB Ok! 1391 queries used.
2 Correct 129 ms 556 KB Ok! 1439 queries used.
3 Correct 122 ms 564 KB Ok! 1579 queries used.
4 Correct 139 ms 632 KB Ok! 1481 queries used.
# Verdict Execution time Memory Grader output
1 Correct 138 ms 504 KB Ok! 1481 queries used.
2 Correct 135 ms 604 KB Ok! 1486 queries used.
3 Correct 119 ms 556 KB Ok! 1552 queries used.
4 Correct 118 ms 556 KB Ok! 1481 queries used.
# Verdict Execution time Memory Grader output
1 Correct 121 ms 572 KB Ok! 1563 queries used.
2 Correct 121 ms 504 KB Ok! 1572 queries used.
3 Correct 126 ms 564 KB Ok! 1588 queries used.
4 Correct 123 ms 504 KB Ok! 1566 queries used.
5 Correct 120 ms 504 KB Ok! 1508 queries used.
6 Correct 123 ms 504 KB Ok! 1526 queries used.
# Verdict Execution time Memory Grader output
1 Correct 123 ms 632 KB Ok! 1562 queries used.
2 Correct 121 ms 560 KB Ok! 1438 queries used.