답안 #605528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605528 2022-07-25T18:40:52 Z Vanilla CEOI16_icc (CEOI16_icc) C++17
90 / 100
177 ms 592 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();
        // shuffle (bt.begin(), bt.end(), std::default_random_engine(std::chrono::system_clock::now().time_since_epoch().count()));
        vector <int> a,b;
        for (int i = 0; i < 8; 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)) {
                a = v1, b = v2;
                break;
            }
        }
        // shuffle (a.begin(), a.end(), std::default_random_engine(std::chrono::system_clock::now().time_since_epoch().count()));
        // shuffle (b.begin(), b.end(), std::default_random_engine(std::chrono::system_clock::now().time_since_epoch().count()));
        int l = 0, r = a.size(), rs1 = -1, rs2 = -1;
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        // reverse(a.begin(), a.end());
        reverse(b.begin(), b.end());
        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;
            }
            else {
                l = mid + 1;
            }
        }
        l = 0, r = b.size();
        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;
            }
            else {
                l = mid + 1;
            }
        }
        merge(rs1, rs2);
        setRoad(rs1, rs2);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 468 KB Ok! 105 queries used.
2 Correct 8 ms 468 KB Ok! 109 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 592 KB Ok! 541 queries used.
2 Correct 53 ms 480 KB Ok! 668 queries used.
3 Correct 54 ms 484 KB Ok! 669 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 504 KB Ok! 1422 queries used.
2 Correct 132 ms 508 KB Ok! 1647 queries used.
3 Correct 141 ms 496 KB Ok! 1625 queries used.
4 Correct 130 ms 500 KB Ok! 1500 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 504 KB Ok! 1512 queries used.
2 Correct 165 ms 508 KB Ok! 1494 queries used.
3 Correct 144 ms 504 KB Ok! 1655 queries used.
4 Correct 138 ms 508 KB Ok! 1457 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 500 KB Ok! 1668 queries used.
2 Correct 174 ms 508 KB Ok! 1672 queries used.
3 Correct 125 ms 508 KB Ok! 1623 queries used.
4 Correct 177 ms 508 KB Ok! 1643 queries used.
5 Correct 141 ms 504 KB Ok! 1461 queries used.
6 Correct 137 ms 508 KB Ok! 1579 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 164 ms 504 KB Too many queries! 1670 out of 1625
2 Halted 0 ms 0 KB -