답안 #688546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
688546 2023-01-27T16:42:55 Z nhphucqt CEOI16_icc (CEOI16_icc) C++17
18 / 100
153 ms 620 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];
int tnLef, tnRig;
int tmpLef[N], tmpRig[N];
vector<int> comp[N];

int root (int x) {
    // cerr << " !! " << x << '\n';
    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 arrCopy(int sizA, int A[], int &sizB, int B[]) {
    for (int i = 0; i < sizA; ++i) {
        B[i] = A[i];
    }
    sizB = sizA;
}

void divide(int sizA, int A[], int &sizB, int B[], int &sizC, int C[]) {
    sizB = sizC = 0;
    for (int i = 0; i < sizA/2; ++i) {
        B[sizB++] = A[i];
    }
    for (int i = sizA/2; i < sizA; ++i) {
        C[sizC++] = A[i];
    }
}

void makeQuery() {
    while (nLef > 1 || nRig > 1) {
        tnLef = tnRig = 0;
        for (int i = (nLef+1)/2; i < nLef; ++i) {
            tmpLef[tnLef++] = lef[i];
        }
        for (int i = (nRig+1)/2; i < nRig; ++i) {
            tmpRig[tnRig++] = rig[i];
        }
        nLef = (nLef+1)/2;
        nRig = (nRig+1)/2;
        if (query(nLef, tnRig, lef, tmpRig) == 1) {
            arrCopy(tnRig, tmpRig, nRig, rig);
        } else if (query(tnLef, nRig, tmpLef, rig) == 1) {
            arrCopy(tnLef, tmpLef, nLef, lef);
        } else if (query(tnLef, tnRig, tmpLef, tmpRig) == 1) {
            arrCopy(tnLef, tmpLef, nLef, lef);
            arrCopy(tnRig, tmpRig, nRig, rig);
        }
        // cerr << "Make query: " << query(nLef, nRig, lef, rig) << '\n';
    }
}

void run(int numNode) {
    cerr << numNode << '\n';
    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) {
            // cerr << " >> " << i << '\n';
            if (i == root(i)) {
                total[nTotal++] = i;
            }
        }
        // cerr << "Total : ";
        // for (int i = 0; i < nTotal; ++i) {
        //     cerr << total[i] << ' ';
        // } cerr << '\n';
        for (int j = 0; j < 8; ++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;
                    }
                }
            }
            // cerr << "lef: ";
            // for (int i = 0; i < nLef; ++i) {
            //     cerr << lef[i] << ' ';
            // }
            // cerr << '\n';
            // cerr << "rig: ";
            // for (int i = 0; i < nRig; ++i) {
            //     cerr << rig[i] << ' ';
            // }
            // cerr << '\n';
            if (query(nLef, nRig, lef, rig) == 1) {
                break;
            }
            // cerr << "---\n";
        }

        // cerr << "First term: " << query(nLef, nRig, lef, rig) << '\n';

        makeQuery();

        int rootA = root(lef[0]);
        int rootB = root(rig[0]);
        nLef = nRig = 0;
        for (int i = 1; i <= numNode; ++i) {
            if (root(i) == rootA) {
                lef[nLef++] = i;
            } else if (root(i) == rootB) {
                rig[nRig++] = i;
            }
        }

        makeQuery();

        assert(nLef == 1 && nRig == 1);

        // cerr << query(nLef, nRig, lef, rig) << '\n';
        
        // cerr << "Set road: " << lef[0] << ' ' << rig[0] << '\n';
        setRoad(lef[0], rig[0]);
        unite(lef[0], rig[0]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 468 KB Ok! 225 queries used.
2 Correct 8 ms 468 KB Ok! 259 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 468 KB Ok! 1180 queries used.
2 Correct 49 ms 480 KB Ok! 1214 queries used.
3 Correct 51 ms 468 KB Ok! 1266 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 143 ms 488 KB Too many queries! 3283 out of 2250
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 488 KB Too many queries! 2994 out of 2000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 151 ms 468 KB Too many queries! 3198 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 153 ms 620 KB Too many queries! 3200 out of 1625
2 Halted 0 ms 0 KB -