Submission #817110

# Submission time Handle Problem Language Result Execution time Memory
817110 2023-08-09T09:34:00 Z anton ICC (CEOI16_icc) C++17
Compilation error
0 ms 0 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();
    }
}

signed main(){
    cin>>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++){
      |                             ~^~~~~~~~~~
/usr/bin/ld: /tmp/cc57WzQq.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccGNjd4p.o:icc.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc57WzQq.o: in function `main':
grader.cpp:(.text.startup+0x17): undefined reference to `run'
collect2: error: ld returned 1 exit status