Submission #117640

# Submission time Handle Problem Language Result Execution time Memory
117640 2019-06-17T02:47:35 Z minhtung0404 ICC (CEOI16_icc) C++17
100 / 100
125 ms 676 KB
//https://oj.uz/problem/view/CEOI16_icc

#include<bits/stdc++.h>
#include "icc.h"
const int N = 105;
using namespace std;

vector <int> mv[N];
int pset[N], cnt = 0;

int find(int i) {return ((pset[i] == i) ? i : pset[i] = find(pset[i]));}

void dsu(int i, int j){
    i = find(i); j = find(j);
    if (i == j) return;
    if (mv[i].size() > mv[j].size()) swap(i, j);
    for (auto x : mv[i]) mv[j].push_back(x);
    pset[i] = j; mv[i].clear();
}

bool query(vector <int> &a, vector <int> &b){
    int A[N], B[N], siza = a.size(), sizb = b.size();
    for (int i = 0; i < siza; i++) A[i] = a[i];
    for (int i = 0; i < sizb; i++) B[i] = b[i];
    return query(siza, sizb, A, B);
}

void find(int l, int r, vector <int>&a, vector <int>& b){
    if (l == r){
        a[0] = a[l]; a.resize(1); return;
    }
    int mid = (l + r) >> 1;
    vector <int> x; for (int i = l; i <= mid; i++) x.push_back(a[i]);
    if (query(x, b)) find(l, mid, a, b);
    else find(mid+1, r, a, b);
}

void cal(vector <int>& a, vector <int>& b){
    find(0, (int)a.size()-1, a, b); find(0, (int)b.size()-1, b, a);
    setRoad(a[0], b[0]); dsu(a[0], b[0]);
}

void run(int n){
    for (int i = 1; i <= n; i++) pset[i] = i, mv[i].push_back(i);
    while (1){
        vector <int> A;
        for (int i = 1; i <= n; i++) if (pset[i] == i) A.push_back(i);
        for (int i = 0; (1 << i) < (int)A.size(); i++){
            vector <int> a, b;
            for (int j = 0; j < (int)A.size(); j++){
                if ((j >> i)&1){
                    for (auto x : mv[A[j]]) a.push_back(x);
                }
                else{
                    for (auto x : mv[A[j]]) b.push_back(x);
                }
            }
            if (query(a, b)){
                cal(a, b); break;
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Ok! 99 queries used.
2 Correct 7 ms 512 KB Ok! 94 queries used.
# Verdict Execution time Memory Grader output
1 Correct 32 ms 512 KB Ok! 521 queries used.
2 Correct 43 ms 556 KB Ok! 654 queries used.
3 Correct 42 ms 512 KB Ok! 652 queries used.
# Verdict Execution time Memory Grader output
1 Correct 106 ms 564 KB Ok! 1419 queries used.
2 Correct 124 ms 512 KB Ok! 1595 queries used.
3 Correct 120 ms 572 KB Ok! 1583 queries used.
4 Correct 113 ms 632 KB Ok! 1514 queries used.
# Verdict Execution time Memory Grader output
1 Correct 115 ms 632 KB Ok! 1454 queries used.
2 Correct 125 ms 556 KB Ok! 1584 queries used.
3 Correct 125 ms 676 KB Ok! 1597 queries used.
4 Correct 107 ms 512 KB Ok! 1482 queries used.
# Verdict Execution time Memory Grader output
1 Correct 120 ms 564 KB Ok! 1581 queries used.
2 Correct 122 ms 560 KB Ok! 1573 queries used.
3 Correct 123 ms 632 KB Ok! 1606 queries used.
4 Correct 118 ms 632 KB Ok! 1567 queries used.
5 Correct 111 ms 560 KB Ok! 1427 queries used.
6 Correct 120 ms 512 KB Ok! 1523 queries used.
# Verdict Execution time Memory Grader output
1 Correct 123 ms 512 KB Ok! 1601 queries used.
2 Correct 123 ms 556 KB Ok! 1611 queries used.