답안 #960434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960434 2024-04-10T13:02:29 Z Ghetto CEOI16_icc (CEOI16_icc) C++17
0 / 100
2 ms 604 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
using pii = pair<int, int>;
const int MAX_N = 100 + 5;

int n;

int par[MAX_N];
vector<int> mems[MAX_N];
void init() {
    for (int i = 1; i <= n; i++) {
        par[i] = i;
        mems[i].push_back(i);
    }
}
int find_par(int u) {
    if (par[u] == u) return u;
    par[u] = find_par(par[u]);
    return par[u];
}
void merge(int u, int v) {
    u = find_par(u);
    v = find_par(v);
    assert(u != v);
    
    if (mems[u].size() < mems[v].size()) swap(u, v);
    par[v] = u;
    for (int mem : mems[v]) mems[u].push_back(mem);
}

bool safe_query(vector<int> els1, vector<int> els2) {
    int size1 = els1.size(), size2 = els2.size();
    int el1[size1], el2[size2];
    for (int i = 0; i < size1; i++) el1[i] = els1[i];
    for (int i = 0; i < size2; i++) el2[i] = els2[i];
    return query(size1, size2, el1, el2);
}

int bin_search(vector<int> els1, vector<int> els2) {
    int lo = 0, hi = els1.size() - 1;
    while (lo != hi) {
        int mid = (lo + hi) / 2;
        vector<int> tmp_els1;
        for (int i = lo; i <= mid; i++) tmp_els1.push_back(els1[i]);
        bool resp = safe_query(tmp_els1, els2);

        if (resp) hi = mid;
        else lo = mid + 1;
    }
    return lo;
}

void do_time() {
    vector<int> nodes;
    for (int i = 1; i <= n; i++)
        if (find_par(i) == i) nodes.push_back(i);
    int n_nodes = nodes.size();
    assert(n_nodes >= 2);

    vector<pii> ones = {{0, (n_nodes - 1) / 2}};
    vector<pii> twos = {{(n_nodes - 1) / 2 + 1, n_nodes - 1}};
    while (true) {
        vector<int> tmp_ones, tmp_twos;
        for (pii range : ones)
            for (int i = range.first; i <= range.second; i++)
                for (int u : mems[nodes[i]])
                    tmp_ones.push_back(u);
        for (pii range : twos)
            for (int i = range.first; i <= range.second; i++)
                for (int u : mems[nodes[i]])
                    tmp_twos.push_back(u);
        bool resp = safe_query(tmp_ones, tmp_twos);

        if (resp) break;
        vector<pii> new_ones, new_twos;
        for (pii range : ones) {
            int lo = range.first, hi = range.second;
            if (lo == hi) continue;
            int mid = (lo + hi) / 2;
            new_ones.push_back({lo, mid});
            new_twos.push_back({mid + 1, hi});
        }
        for (pii range : twos) {
            int lo = range.first, hi = range.second;
            if (lo == hi) continue;
            int mid = (lo + hi) / 2;
            new_ones.push_back({lo, mid});
            new_twos.push_back({mid + 1, hi});
        }
        ones.swap(new_ones);
        twos.swap(new_twos);
    }

    vector<int> one_nodes, two_nodes;
    for (pii range : ones)
        for (int i = range.first; i <= range.second; i++)
            for (int u : mems[nodes[i]])
                one_nodes.push_back(u);
    for (pii range : twos)
        for (int i = range.first; i <= range.second; i++)
            for (int u : mems[nodes[i]])
                two_nodes.push_back(u);
    int one_ans = bin_search(one_nodes, two_nodes);
    int two_ans = bin_search(two_nodes, one_nodes);
    setRoad(one_ans, two_ans);
    merge(one_ans, two_ans);    
}

void run(int tmp_n) {
    n = tmp_n;

    init();

    for (int i = 1; i <= n - 1; i++) do_time();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Wrong road!
2 Halted 0 ms 0 KB -