Submission #94984

# Submission time Handle Problem Language Result Execution time Memory
94984 2019-01-26T13:10:33 Z georgerapeanu ICC (CEOI16_icc) C++11
18 / 100
234 ms 760 KB
#include "icc.h"

#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <iostream>

using namespace std;

vector<vector<int>> components;

int a[200],len_a;
int b[200],len_b;
int c[200],len_c;
int d[200],len_d;

const int LIM = 2;

int n;
int adia[200][200];
int curr[200][200];

int pre_query(int len_a,int len_b,int a[],int b[]){

    if(len_a == 0 || len_b == 0){
        return 0;
    }

    bool is_true = false;

    for(int i = 1;i <= len_a;i++){
        for(int j = 1;j <= len_b;j++){
            is_true |= (adia[a[i]][b[j]] == 1);
            if(adia[a[i]][b[j]] == 1){
     //           cout << "bag pula " << a[i] << " " << b[j] << "\n";
            }
        }
    }

    if(is_true == true){
    //    return 1;
    }
    //for(int i = 1;i <= len_a;i++)cout << a[i] << " ";cout << "\n";
    //for(int i = 1;i <= len_b;i++)cout << b[i] << " ";cout << "\n";


    return query(len_a,len_b,a,b);
}

int my_query(vector<int> &c1,vector<int> &c2){
    
    len_a = 0;
    for(auto it:c1){
        a[len_a++] = it;
    }

    len_b = 0;
    for(auto it:c2){
        b[len_b++] = it;
    }

    return pre_query(len_a,len_b,a,b);
}

int my_query(vector< vector<int> > &c1,vector< vector<int> > &c2){
    len_a = 0;
    for(auto it:c1){
        for(auto it2:it){
            a[len_a++] = it2;
        }
    }
    
    len_b = 0;
    for(auto it:c2){
        for(auto it2:it){
            b[len_b++] = it2;
        }
    }

    if(len_a == 0 || len_b == 0){
        return 0;
    }

    return pre_query(len_a,len_b,a,b);
}

void run(int N){
    n = N;

    srand(time(NULL));
    for(int i = 1;i <= n;i++){
        components.push_back({i});    
    } 

    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
        //    adia[i][j] = -1 + (i == j);
        }
    }
    
    for(int t = 1;t < n;t++){
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= n;j++){
          //      curr[i][j] = adia[i][j];
            }
        }
        random_shuffle(components.begin(),components.end());
        vector<vector<int>> c1,c2;
        for(int i = 0;i < (int)components.size() / 2;i++){
            c1.push_back(components[i]);
        }
        for(int i = (int)components.size() / 2;i < (int)components.size();i++){
            c2.push_back(components[i]);
        }

        while(c1.size() + c2.size() > LIM){

            while(my_query(c1,c2) == 0){
                random_shuffle(c1.begin(),c1.end());
                random_shuffle(c2.begin(),c2.end());
    
                vector<vector<int>> nc1,nc2;
            
                for(int i = 0;i < (int)c1.size() / 2;i++){
                    nc1.push_back(c1[i]);
                }

                for(int i = (int)c1.size() / 2;i < (int)c1.size();i++){
                    nc2.push_back(c1[i]);
                }

                for(int i = 0;i < (int)c2.size() / 2;i++){
                    nc1.push_back(c2[i]);
                }

                for(int i = (int)c2.size() / 2;i < (int)c2.size();i++){
                    nc2.push_back(c2[i]);
                }

                swap(c1,nc1);
                swap(c2,nc2);
            }

            vector<vector<int>> nc1,nc2,nc3,nc4;
            
            for(int i = 0;i < (int)c1.size() / 2;i++){
                nc1.push_back(c1[i]);
            }

            for(int i = (int)c1.size() / 2;i < (int)c1.size();i++){
                nc2.push_back(c1[i]);
            }

            for(int i = 0;i < (int)c2.size() / 2;i++){
                nc3.push_back(c2[i]);
            }

            for(int i = (int)c2.size() / 2;i < (int)c2.size();i++){
                nc4.push_back(c2[i]);
            }
        
            if(my_query(nc1,nc3)){
                swap(c1,nc1);
                swap(c2,nc3);
            }
            else if(my_query(nc1,nc4)){
                swap(c1,nc1);
                swap(c2,nc4);
            }
            else if(my_query(nc2,nc3)){
                swap(c1,nc2);
                swap(c2,nc3);
            }
            else{
                swap(c1,nc2);
                swap(c2,nc4);
            }
        }
        
        vector<int> fst_comp = c1[0];
        vector<int> snd_comp = c2[0];

        for(auto &it:components){
            if(it == snd_comp){
                swap(it,components.back());
            }
        }

        components.pop_back();

        for(auto &it:components){
            if(it == fst_comp){
                for(auto it2:snd_comp){
                    it.push_back(it2);
                }
            }
        }

        while((int)fst_comp.size() + (int)snd_comp.size() > LIM){
            vector<int> nc1,nc2,nc3,nc4;

            for(int i = 0;i < (int)fst_comp.size() / 2;i++){
                nc1.push_back(fst_comp[i]);
            }

            for(int i = (int)fst_comp.size() / 2;i < (int)fst_comp.size();i++){
                nc2.push_back(fst_comp[i]);
            }
            
            for(int i = 0;i < (int)snd_comp.size() / 2;i++){
                nc3.push_back(snd_comp[i]);
            }

            for(int i = (int)snd_comp.size() / 2;i < (int)snd_comp.size();i++){
                nc4.push_back(snd_comp[i]);
            }

            if(my_query(nc1,nc3)){
                swap(fst_comp,nc1);
                swap(snd_comp,nc3);
            }
            else if(my_query(nc1,nc4)){
                swap(fst_comp,nc1);
                swap(snd_comp,nc4);
            }
            else if(my_query(nc2,nc3)){
                swap(fst_comp,nc2);
                swap(snd_comp,nc3);
            }
            else{
                swap(fst_comp,nc2);
                swap(snd_comp,nc4);
            }
        }
       // printf("%d %d\n",fst_comp[0],snd_comp[0]);
        setRoad(fst_comp[0],snd_comp[0]);
        adia[fst_comp[0]][snd_comp[0]] = 1;
        adia[snd_comp[0]][fst_comp[0]] = 1;
        for(auto it:components){
            for(auto it2:it){
                for(auto it3:it){
    //                adia[it2][it3] = (adia[it2][it3] == 1 ? 1:0);
                }
            }
        }
    }
}


Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:243:26: warning: unused variable 'it3' [-Wunused-variable]
                 for(auto it3:it){
                          ^~~
icc.cpp:242:22: warning: unused variable 'it2' [-Wunused-variable]
             for(auto it2:it){
                      ^~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 508 KB Ok! 153 queries used.
2 Correct 10 ms 504 KB Ok! 148 queries used.
# Verdict Execution time Memory Grader output
1 Correct 63 ms 632 KB Ok! 890 queries used.
2 Correct 72 ms 632 KB Ok! 1055 queries used.
3 Correct 74 ms 504 KB Ok! 1037 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 213 ms 632 KB Too many queries! 2434 out of 2250
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 211 ms 760 KB Too many queries! 2533 out of 2000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 234 ms 688 KB Too many queries! 2608 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 700 KB Too many queries! 2567 out of 1625
2 Halted 0 ms 0 KB -