Submission #96066

# Submission time Handle Problem Language Result Execution time Memory
96066 2019-02-05T15:40:51 Z georgerapeanu ICC (CEOI16_icc) C++11
7 / 100
2000 ms 176652 KB
#include "icc.h"
 
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <iostream>
 
using namespace std;
 
const int NMAX = 1e2;

vector<vector<int>> components;
int label[2 * NMAX + 5];
int inv_label[2 * NMAX + 5];
 
int a[NMAX + 5],len_a;
int b[NMAX + 5],len_b;
int lg2[NMAX + 5];


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;
    }
 
    if(len_a == 0 || len_b == 0){
        return 0;
    }

    return query(len_a,len_b,a,b);
}
 
void run(int n){
    lg2[0] = -1;
    for(int i = 1;i <= n;i++){
        lg2[i] = 1 + lg2[i >> 1];
        components.push_back({i});    
    } 
    for(int t = 1;t < n;t++){
        int last_comp_bit = lg2[(int)components.size() - 1];
        int total_bits = last_comp_bit;
        for(int x = 0;x < (int)components.size();x++){
            for(int i = 0;i < (int)components[x].size();i++){
                label[components[x][i]] = ((i << (lg2[(int)components.size() - 1] + 1) | x));
                inv_label[((i << (lg2[(int)components.size() - 1] + 1) | x))] = components[x][i];
                total_bits = max(total_bits,last_comp_bit + 1 + lg2[i]);
            }
        }

        int m1 = 0;
        int m2 = 0;
        int xo = 0;

        for(int b = 0;b <= last_comp_bit;b++){
            vector<int> v1,v2;
            for(int i = 1;i <= n;i++){
                if((label[i] >> b) & 1){
                    v1.push_back(i);
                }
                else{
                    v2.push_back(i);
                }
            }
            
            xo |= my_query(v1,v2) << b;
        }

        int pos = 0;

        for(int b = 0;b <= last_comp_bit;b++){
            if((xo >> b) & 1){
                m1 = 1 << b;
                pos = b;
                break;
            }
        }

        for(int b = 0;b <= last_comp_bit;b++){
            if(b == pos){
                continue;
            }
            m2 |= ((((xo >> b) & 1)) << b);

            vector<int> v1,v2;

            for(int i = 1;i <= n;i++){
                if(((label[i] >> pos) & 1) == 1 && (((1 << (b + 1)) - 1) & label[i]) == (((1 << (b + 1)) - 1) & m1)){
                    v1.push_back(i);
                }
                else if(((label[i] >> pos) & 1) == 0 && (((1 << (b + 1)) - 1) & label[i]) == (((1 << (b + 1)) - 1) & m2)){
                    v2.push_back(i);
                }
            }

            if(my_query(v1,v2) == 0){
                m1 ^= (1 << b);
                m2 ^= (1 << b);
            }
        }
        
        int fst_comp = (m1 & ((1 << (last_comp_bit + 1)) - 1));
        int snd_comp = (m2 & ((1 << (last_comp_bit + 1)) - 1));
       
        int pref1 = -1,pref2 = -1;

        for(int b = total_bits;b >= 0;b--){
            if(pref1 + (1 << b) < (int)components[fst_comp].size()){
                vector<int> v;
                for(int i = 0;i <= pref1 + (1 << b);i++){
                    v.push_back(components[fst_comp][i]);
                }
                if(my_query(components[snd_comp],v) == 0){
                    pref1 += (1 << b);
                }
            }
        }
        
        for(int b = total_bits;b >= 0;b--){
            if(pref2 + (1 << b) < (int)components[snd_comp].size()){
                vector<int> v;
                for(int i = 0;i <= pref2 + (1 << b);i++){
                    v.push_back(components[snd_comp][i]);
                }
                if(my_query(components[fst_comp],v) == 0){
                    pref2 += (1 << b);
                }
            }
        }

        int u = components[fst_comp][pref1 + 1];
        int v = components[snd_comp][pref2 + 1];
        
        setRoad(u,v);
        
        for(auto it:components[fst_comp]){
            components[snd_comp].push_back(it);
        }
        swap(components[fst_comp],components.back());
        components.pop_back();
    }
}
 
# Verdict Execution time Memory Grader output
1 Correct 9 ms 632 KB Ok! 135 queries used.
2 Correct 9 ms 504 KB Ok! 135 queries used.
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 110 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 504 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 176652 KB Time limit exceeded
2 Halted 0 ms 0 KB -