Submission #817112

# Submission time Handle Problem Language Result Execution time Memory
817112 2023-08-09T09:34:40 Z anton ICC (CEOI16_icc) C++17
61 / 100
123 ms 624 KB
#include<bits/stdc++.h>
#include "icc.h"

using namespace std;
#define pii pair<int, int>

const int MAX_N = 1e2;
int n;
vector<int> groups[MAX_N+1];
int dsu[MAX_N+1];

int my_query(int sa, int sb, int a[], int b[]){
    for(int i = 0; i<sa; i++){
        //cout<<a[i]<<" ";
    }
    //cout<<endl<<"__"<<endl;
    for(int i = 0; i<sb; i++){
        //cout<<b[i]<<" ";
    }
    //cout<<endl;
    int res;
    //cin>>res;
    res = query(sa, sb, a, b);
    return res;
}

void merge(int a, int b){
    int ga =  dsu[a];
    int gb = dsu[b];

    if(ga==gb){
        return;
    }
    if(ga>gb){
        swap(ga, gb);
    }

    for(auto e: groups[gb]){
        groups[ga].push_back(e);
        dsu[e] = ga;
    }
    groups[gb].clear();
}

void my_setRoad(int a, int b){
    merge(a, b);
    setRoad(a, b);
    //cout<<"road "<<a<<" "<<b<<endl;
}

void pbv(vector<int>& a, vector<int>&b){
    a.insert(a.end(), b.begin(), b.end());
}

vector<int> all_except(int id){
    vector<int> b;
    
    
    for(int i = 0; i<n; i++){
        if(i!=id){
            pbv(b, groups[i]);
        }
    }
    return b;
}
int query_group(int id){
    vector<int> a;
    pbv(a, groups[id]);
    vector<int> b = all_except(id);

    return my_query(a.size(), b.size(),&a[0], &b[0]);
}

void find(vector<int>& a, vector<int>& b){
    int aid = -1;
    
    
    for(int step = (1<<7); step>=1; step/=2){
        if(aid+step<a.size()){
            if(aid+step==0){
                aid+=step;
                continue;
            }
            ////cout<<"qa"<<endl;
            if(my_query(a.size()-aid-step, b.size(), &a[aid+step], &b[0])){
                aid+=step;
            }
        }
    }

    int bid= -1;
    for(int step = (1<<7); step>=1; step/=2){
        if(bid+step<b.size()){
            if(bid+step==0){
                bid+=step;
                continue;
            }
            if(my_query(1, b.size()-bid-step, &a[aid], &b[bid+step])){
                bid+=step;
            }
        }
    }
    ////cout<<aid<<" "<<bid<<endl;

    my_setRoad(a[aid], b[bid]);
}

pair<vector<int>, vector<int>> get_split(){

    pair<vector<int>, vector<int>> pv;
    vector<int> gs;
    for(int i = 0; i<n; i++){
        if(groups[i].size()>0){
            gs.push_back(i);
        }
    }
    random_shuffle(gs.begin(), gs.end());
    for(int i= 0; i<gs.size()/2; i++){
        pbv(pv.first, groups[gs[i]]);
    }
    for(int i= gs.size()/2; i<gs.size(); i++){
        pbv(pv.second, groups[gs[i]]);
    }
    if(pv.first.size()>0&& pv.second.size()>0){
        return pv;
    }
    else{
        return get_split();
    }
}

void run(int N){
    n=N;
    srand(42);

    for(int i = 0; i<n; i++){
        dsu[i+1] = i;
        groups[i].push_back(i+1);
    }

    for(int i = 0; i<n-1; i++){
        /*for(int i = 0; i<n; i++){
            if(groups[i].size()>0){
                if(query_group(i)==1){
                    auto tmp = all_except(i);
                    find(groups[i], tmp);
                }
            }
        }*/

        auto pvv = get_split();
        //cout<<"ok"<<endl;

        while(!my_query(pvv.first.size(), pvv.second.size(), &pvv.first[0], &pvv.second[0])){
            pvv = get_split();
        }
        find(pvv.first, pvv.second);
    }
}

Compilation message

icc.cpp: In function 'void find(std::vector<int>&, std::vector<int>&)':
icc.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         if(aid+step<a.size()){
      |            ~~~~~~~~^~~~~~~~~
icc.cpp:93:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         if(bid+step<b.size()){
      |            ~~~~~~~~^~~~~~~~~
icc.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > get_split()':
icc.cpp:118:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for(int i= 0; i<gs.size()/2; i++){
      |                   ~^~~~~~~~~~~~
icc.cpp:121:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for(int i= gs.size()/2; i<gs.size(); i++){
      |                             ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Ok! 105 queries used.
2 Correct 4 ms 468 KB Ok! 108 queries used.
# Verdict Execution time Memory Grader output
1 Correct 23 ms 500 KB Ok! 559 queries used.
2 Correct 35 ms 496 KB Ok! 850 queries used.
3 Correct 34 ms 500 KB Ok! 796 queries used.
# Verdict Execution time Memory Grader output
1 Correct 87 ms 508 KB Ok! 1565 queries used.
2 Correct 123 ms 492 KB Ok! 2144 queries used.
3 Correct 104 ms 508 KB Ok! 1724 queries used.
4 Correct 91 ms 512 KB Ok! 1736 queries used.
# Verdict Execution time Memory Grader output
1 Correct 89 ms 496 KB Ok! 1699 queries used.
2 Correct 88 ms 504 KB Ok! 1669 queries used.
3 Correct 97 ms 624 KB Ok! 1870 queries used.
4 Correct 88 ms 496 KB Ok! 1639 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 504 KB Too many queries! 1957 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 588 KB Too many queries! 1932 out of 1625
2 Halted 0 ms 0 KB -