답안 #605475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605475 2022-07-25T18:12:54 Z Vanilla CEOI16_icc (CEOI16_icc) C++17
0 / 100
126 ms 1240 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;
    }
}
 
map <pair <vector <int> ,vector <int> >, int > mp;
 
int qq (vector <int> a, vector <int> b) {
    if (mp.count({a, b})) return mp[{a,b}];
    return mp[{a, b}] = 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> bt (k);
        iota(bt.begin(), bt.end(), 0);
        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: bt){
            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() - 1, rs1 = -1, rs2 = -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);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 528 KB Ok! 543 queries used.
2 Incorrect 17 ms 572 KB Wrong road!
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 1100 KB Ok! 1411 queries used.
2 Incorrect 16 ms 592 KB Wrong road!
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 784 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 126 ms 1240 KB Wrong road!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 716 KB Wrong road!
2 Halted 0 ms 0 KB -