Submission #688558

# Submission time Handle Problem Language Result Execution time Memory
688558 2023-01-27T17:40:53 Z nhphucqt ICC (CEOI16_icc) C++17
100 / 100
101 ms 608 KB
#include <bits/stdc++.h>
#include "icc.h"

using namespace std;

const int N = 107;
int fa[N];
int nTotal, nLef, nRig;
int total[N], lef[N], rig[N];
vector<int> comp[N];

int root (int x) {
    return fa[x] < 0 ? x : fa[x] = root(fa[x]);
}

void unite(int u, int v) {
    u = root(u);
    v = root(v);
    assert(u != v);
    if (fa[u] > fa[v]) {
        swap(u, v);
    }
    fa[u] += fa[v];
    fa[v] = u;
    for (int x : comp[v]) {
        comp[u].push_back(x);
    }
}

void makeQuery() {
    while (nLef > 1) {
        if (query((nLef+1)/2, nRig, lef, rig) == 1) {
            nLef = (nLef+1)/2;
        } else {
            int cLef = 0;
            for (int i = (nLef+1)/2; i < nLef; ++i) {
                lef[cLef++] = lef[i];
            }
            nLef = cLef;
        }
    }
    while (nRig > 1) {
        if (query(nLef, (nRig+1)/2, lef, rig) == 1) {
            nRig = (nRig+1)/2;
        } else {
            int cRig = 0;
            for (int i = (nRig+1)/2; i < nRig; ++i) {
                rig[cRig++] = rig[i];
            }
            nRig = cRig;
        }
    }
}

void run(int numNode) {
    memset(fa, -1, (numNode+1) * sizeof(int));
    for (int i = 1; i <= numNode; ++i) {
        comp[i].push_back(i);
    }
    int numComp = numNode;
    while (numComp-- > 1) {
        nTotal = 0;
        for (int i = 1; i <= numNode; ++i) {
            if (i == root(i)) {
                total[nTotal++] = i;
            }
        }
        for (int j = 0; j < 7; ++j) {
            nLef = nRig = 0;
            for (int i = 0; i < nTotal; ++i) {
                if ((i>>j) & 1) {
                    for (int x : comp[total[i]]) {
                        lef[nLef++] = x;
                    }
                } else {
                    for (int x : comp[total[i]]) {
                        rig[nRig++] = x;
                    }
                }
            }
            if (31 - __builtin_clz(nTotal-1) == j) {
                break;
            }
            if (query(nLef, nRig, lef, rig) == 1) {
                break;
            }
        }
        makeQuery();
        assert(nLef == 1 && nRig == 1);
        setRoad(lef[0], rig[0]);
        unite(lef[0], rig[0]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Ok! 98 queries used.
2 Correct 4 ms 468 KB Ok! 96 queries used.
# Verdict Execution time Memory Grader output
1 Correct 25 ms 468 KB Ok! 534 queries used.
2 Correct 29 ms 468 KB Ok! 616 queries used.
3 Correct 29 ms 476 KB Ok! 606 queries used.
# Verdict Execution time Memory Grader output
1 Correct 92 ms 468 KB Ok! 1430 queries used.
2 Correct 93 ms 484 KB Ok! 1513 queries used.
3 Correct 95 ms 488 KB Ok! 1589 queries used.
4 Correct 94 ms 480 KB Ok! 1468 queries used.
# Verdict Execution time Memory Grader output
1 Correct 92 ms 468 KB Ok! 1503 queries used.
2 Correct 94 ms 608 KB Ok! 1492 queries used.
3 Correct 91 ms 480 KB Ok! 1537 queries used.
4 Correct 93 ms 468 KB Ok! 1494 queries used.
# Verdict Execution time Memory Grader output
1 Correct 92 ms 468 KB Ok! 1522 queries used.
2 Correct 91 ms 476 KB Ok! 1513 queries used.
3 Correct 97 ms 588 KB Ok! 1550 queries used.
4 Correct 95 ms 468 KB Ok! 1573 queries used.
5 Correct 92 ms 468 KB Ok! 1460 queries used.
6 Correct 101 ms 484 KB Ok! 1554 queries used.
# Verdict Execution time Memory Grader output
1 Correct 96 ms 480 KB Ok! 1537 queries used.
2 Correct 99 ms 476 KB Ok! 1513 queries used.