Submission #117637

# Submission time Handle Problem Language Result Execution time Memory
117637 2019-06-17T02:38:01 Z minhtung0404 ICC (CEOI16_icc) C++17
90 / 100
314 ms 632 KB
//https://oj.uz/problem/view/CEOI16_icc

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

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;
    pset[i] = j;
}

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(vector <int>&a, vector <int>& b){
    if (a.size() == 1) return;
    int siz = (int)a.size() / 2;
    vector <int> x; x.clear();
    for (int i = 0; i < siz; i++) x.push_back(a[i]);
    cnt++;
    if (!query(x, b)){
        x.clear();
        for (int i = siz; i < (int)a.size(); i++) x.push_back(a[i]);
    }
    a.swap(x);
    find(a, b);
}

void cal(vector <int>& a, vector <int>& b){
    cnt = 0; find(a, b);
    cnt = 0; find(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;
    while (1){
        vector <int> A;
        for (int i = 0; (1 << i) <= n; i++){
            vector <int> a, b;
            for (int j = 1; j <= n; j++){
                if ((find(j) >> i)&1){
                    a.push_back(j);
                }
                else{
                    b.push_back(j);
                }
            }
            if (query(a, b)){
                cal(a, b); break;
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Ok! 103 queries used.
2 Correct 7 ms 512 KB Ok! 101 queries used.
# Verdict Execution time Memory Grader output
1 Correct 34 ms 512 KB Ok! 541 queries used.
2 Correct 42 ms 512 KB Ok! 674 queries used.
3 Correct 42 ms 604 KB Ok! 684 queries used.
# Verdict Execution time Memory Grader output
1 Correct 97 ms 512 KB Ok! 1362 queries used.
2 Correct 142 ms 632 KB Ok! 1656 queries used.
3 Correct 97 ms 596 KB Ok! 1363 queries used.
4 Correct 110 ms 512 KB Ok! 1523 queries used.
# Verdict Execution time Memory Grader output
1 Correct 103 ms 560 KB Ok! 1432 queries used.
2 Correct 111 ms 512 KB Ok! 1503 queries used.
3 Correct 124 ms 632 KB Ok! 1669 queries used.
4 Correct 96 ms 604 KB Ok! 1329 queries used.
# Verdict Execution time Memory Grader output
1 Correct 314 ms 512 KB Ok! 1645 queries used.
2 Correct 127 ms 512 KB Ok! 1676 queries used.
3 Correct 132 ms 556 KB Ok! 1667 queries used.
4 Correct 121 ms 512 KB Ok! 1672 queries used.
5 Correct 107 ms 512 KB Ok! 1438 queries used.
6 Correct 122 ms 552 KB Ok! 1628 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 632 KB Too many queries! 1679 out of 1625
2 Halted 0 ms 0 KB -