Submission #605453

# Submission time Handle Problem Language Result Execution time Memory
605453 2022-07-25T17:56:36 Z Vanilla ICC (CEOI16_icc) C++17
61 / 100
154 ms 596 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
int dsu [maxn];
vector <int> el [maxn];

int dad (int x) {
    return dsu[x] = (x == dsu[x] ? x: dad(dsu[x]));
}

void merge (int x, int y){
    x = dad(x), y = dad(y);
    if (x != y) {
        if (el[x].size() < el[y].size()) swap(x, y);
        for (int j: el[y]) el[x].push_back(j);
        el[y].clear();
        dsu[y] = x;
    }
}

int qq (vector <int> a, vector <int> b) {
    return query(a.size(), b.size(), a.data(), b.data());
}

void run(int n) {
    for (int i = 1; i <= n; i++) {
        dsu[i] = i;
        el[i].push_back(i);
    }
    for (int p = 0; p < n - 1; p++){
        set <int> s;
        vector <int> comp;
        for (int j = 1; j <= n; j++) s.insert(dad(j));
        for (int k: s) comp.push_back(k);
        int m = comp.size();
        int k = ceil(log2(m));
        vector <int> a,b;
        int xr = 0;
        for (int i = 0; i <= k; i++){
            vector <int> v1, v2;
            for (int j = 0; j < m; j++){
                if (j & (1 << i)) for (int l: el[comp[j]]) v1.push_back(l);
                else for (int l: el[comp[j]]) v2.push_back(l);
            }
            if (qq(v1, v2)) {
                xr+=(1 << i);
            }
        }
        set <pair <int, int> > pr;
        for (int i = 0; i < m; i++){
            if ((i ^ xr) >= m) continue;
            pr.insert({min(i, i ^ xr), max(i, i ^ xr)});
        }
        vector <pair <int, int>> ss;
        for (auto [x, y]: pr) ss.push_back({x, y});
        int l = 0, r = pr.size() - 1, rs1 = -1, rs2 = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector <int> v1, v2;
            for (int i = 0; i <= mid; i++) {
                for (int j: el[comp[ss[i].first]]) v1.push_back(j);
                for (int j: el[comp[ss[i].second]]) v2.push_back(j);
            }
            if (qq(v1, v2)) {
                a = el[comp[ss[mid].first]], b = el[comp[ss[mid].second]];
                r = mid - 1;
            }
            else {
                l = mid + 1;
            }
        }
        l = 0, r = a.size() - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector <int> v;
            for (int i = 0; i <= mid; i++) v.push_back(a[i]);
            if (qq(v, b)) {
                rs1 = v.back();
                r = mid - 1;
            }
            else {
                l = mid + 1;
            }
        }
        l = 0, r = b.size() - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector <int> v;
            for (int i = 0; i <= mid; i++) v.push_back(b[i]);
            if (qq(v, a)) {
                rs2 = v.back();
                r = mid - 1;
            }
            else {
                l = mid + 1;
            }
        }
        merge(rs1, rs2);
        setRoad(rs1, rs2);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 468 KB Ok! 149 queries used.
2 Correct 9 ms 468 KB Ok! 145 queries used.
# Verdict Execution time Memory Grader output
1 Correct 41 ms 492 KB Ok! 728 queries used.
2 Correct 41 ms 492 KB Ok! 640 queries used.
3 Correct 36 ms 488 KB Ok! 676 queries used.
# Verdict Execution time Memory Grader output
1 Correct 131 ms 496 KB Ok! 1743 queries used.
2 Correct 115 ms 500 KB Ok! 1482 queries used.
3 Correct 126 ms 512 KB Ok! 1780 queries used.
4 Correct 120 ms 508 KB Ok! 1701 queries used.
# Verdict Execution time Memory Grader output
1 Correct 119 ms 596 KB Ok! 1731 queries used.
2 Correct 154 ms 500 KB Ok! 1745 queries used.
3 Correct 125 ms 468 KB Ok! 1782 queries used.
4 Correct 119 ms 512 KB Ok! 1739 queries used.
# Verdict Execution time Memory Grader output
1 Correct 119 ms 492 KB Ok! 1707 queries used.
2 Incorrect 139 ms 516 KB Too many queries! 1782 out of 1775
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 512 KB Too many queries! 1746 out of 1625
2 Halted 0 ms 0 KB -