Submission #1027907

# Submission time Handle Problem Language Result Execution time Memory
1027907 2024-07-19T11:24:05 Z serifefedartar ICC (CEOI16_icc) C++17
18 / 100
206 ms 684 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 20
const ll MOD = 1e9 + 7;
const ll MAXN = 105;

int par[MAXN], sz[MAXN], temp1[MAXN], temp2[MAXN];
int find(int node) {
    if (node == par[node])
        return node;
    return par[node] = find(par[node]);
}

void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b)
        return ;
    if (sz[b] > sz[a])
        swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
}

int qry(int sz1, int sz2, vector<int> A, vector<int> B) {
    for (int i = 0; i < sz1; i++)
        temp1[i] = A[i];
    for (int i = 0; i < sz2; i++)
        temp2[i] = B[i];
    return query(sz1, sz2, temp1, temp2);
}

bool control = true;
void dac(vector<vector<int>> A, vector<vector<int>> B) {
    if (!control || A.size() == 0 || B.size() == 0)
        return ; 

    vector<int> AA, BB;
    for (auto u : A)
        for (auto v : u)
            AA.push_back(v);
    for (auto u : B)
        for (auto v : u)
            BB.push_back(v);

    if (qry(AA.size(), BB.size(), AA, BB)) {

        while ((int)BB.size() > 1) {
            vector<int> X, Y;
            for (int i = 0; i < (int)BB.size() / 2; i++)
                X.push_back(BB[i]);
            for (int i = (int)BB.size() / 2; i < (int)BB.size(); i++)
                Y.push_back(BB[i]);

            if (qry(AA.size(), X.size(), AA, X))
                BB = X;
            else
                BB = Y;
        }

        while ((int)AA.size() > 1) {
            vector<int> X, Y;
            for (int i = 0; i < (int)AA.size() / 2; i++)
                X.push_back(AA[i]);
            for (int i = (int)AA.size() / 2; i < (int)AA.size(); i++)
                Y.push_back(AA[i]);

            if (qry(X.size(), 1, X, BB))
                AA = X;
            else
                AA = Y;
        }

        setRoad(BB[0], AA[0]);
        unite(BB[0], AA[0]);
        control = false;
    } else {
        vector<vector<int>> new_A1, new_A2;
        vector<vector<int>> new_B1, new_B2;
        for (int i = 0; i < (int)A.size() / 2; i++)
            new_A1.push_back(A[i]);
        for (int i = (int)A.size() / 2; i < (int)A.size(); i++)
            new_A2.push_back(A[i]);
        for (int i = 0; i < (int)B.size() / 2; i++)
            new_B1.push_back(B[i]);
        for (int i = (int)B.size() / 2; i < (int)B.size(); i++)
            new_B2.push_back(B[i]);
        dac(new_A1, new_A2);
        dac(new_B1, new_B2);
    }
}

int n;
void solve() {
    map<int, vector<int>> mp;
    for (int i = 1; i <= n; i++)
        mp[find(i)].push_back(i);

    vector<vector<int>> temp;
    for (auto u : mp)
        temp.push_back(u.s);
    random_shuffle(temp.begin(), temp.end());

    vector<vector<int>> A, B;
    for (int i = 0; i < (int)temp.size() / 2; i++)
        A.push_back(temp[i]);
    for (int i = temp.size() / 2; i < (int)temp.size(); i++)
        B.push_back(temp[i]);
    control = true;
    dac(A, B);
}

void run(int N) {
    n = N;
    for (int i = 1; i <= N; i++)
        sz[i] = 1, par[i] = i;
    for (int i = 1; i < N; i++)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Ok! 104 queries used.
2 Correct 5 ms 604 KB Ok! 106 queries used.
# Verdict Execution time Memory Grader output
1 Correct 31 ms 668 KB Ok! 834 queries used.
2 Correct 50 ms 668 KB Ok! 1338 queries used.
3 Correct 53 ms 668 KB Ok! 1349 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 600 KB Number of queries more than 4500 out of 2250
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 684 KB Number of queries more than 4000 out of 2000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 684 KB Number of queries more than 3550 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 664 KB Number of queries more than 3250 out of 1625
2 Halted 0 ms 0 KB -