Submission #984692

# Submission time Handle Problem Language Result Execution time Memory
984692 2024-05-17T02:55:21 Z FZ_Melo ICC (CEOI16_icc) C++14
100 / 100
86 ms 868 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> comp;
vector<vector<int>> nums;

int loga(int x){    
    int cnt=0;
    while((1<<(cnt+1))<=x)
        cnt++;
    return cnt;
}

int buscaComp(vector<pair<int, int>> &maybe){
    int l=0, r=maybe.size()-1;
    while(l<r){
        int mid=(l+r)/2;
        int ar1[101], ar2[101];
        int p1=0, p2=0;
        for(int i=l; i<=mid; i++){
            for(int x: nums[comp[maybe[i].first]])
                ar1[p1++]=x;
            for(int x: nums[comp[maybe[i].second]])
                ar2[p2++]=x;
        }
        if(query(p1, p2, ar1, ar2))
            r=mid;
        else
            l=mid+1;
    }
    return l;
}

int buscaNode(int c1, int c2){
    int p2=0;
    int ar2[101];
    for(int x: nums[comp[c2]])
        ar2[p2++]=x;
    int l=0, r=nums[comp[c1]].size()-1;
    while(l<r){
        int mid=(l+r)/2;
        int p1=0;
        int ar1[101];
        for(int i=l; i<=mid; i++)
            ar1[p1++]=nums[comp[c1]][i];
        if(query(p1, p2, ar1, ar2))
            r=mid;
        else
            l=mid+1;
    }
    return nums[comp[c1]][l];
}

void buscaAri(){
    int logn= loga(comp.size());
    int w=0;
    for(int k=0; k<=logn; k++){
        int p1=0, p2=0;
        int ar1[101], ar2[101];
        for(int i=0; i<comp.size(); i++){
            if((1<<k)&i){
                for(int x: nums[comp[i]])
                    ar1[p1++]=x;
            }
            else{
                for(int x: nums[comp[i]])
                    ar2[p2++]=x;
            }
        }
        if(query(p1, p2, ar1, ar2))
            w|=(1<<k);
    }
    
    vector<pair<int, int>> maybe;
    for(int i=0; i<comp.size(); i++){
        int j=w^i;
        if(i<j && j<comp.size()){
            maybe.push_back({i, j});
        }
    }

    int pos=buscaComp(maybe);
    int c1=maybe[pos].first, c2=maybe[pos].second;
    int a=1, b=1;
    a=buscaNode(c1, c2);
    b=buscaNode(c2, c1);
    for(int x: nums[comp[c2]])
        nums[comp[c1]].push_back(x);
    comp.erase(comp.begin()+c2);
    setRoad(a, b);
}


void run(int N){
    n=N;
    nums.clear();
    comp.clear();
    nums.resize(n+1);
    for(int i=1; i<=n; i++){
        nums[i].push_back(i);
        comp.push_back(i);
    }
    for(int i=0; i<n-1; i++){
        buscaAri();
    }
}

Compilation message

icc.cpp: In function 'void buscaAri()':
icc.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int i=0; i<comp.size(); i++){
      |                      ~^~~~~~~~~~~~
icc.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=0; i<comp.size(); i++){
      |                  ~^~~~~~~~~~~~
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(i<j && j<comp.size()){
      |                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Ok! 112 queries used.
2 Correct 4 ms 604 KB Ok! 110 queries used.
# Verdict Execution time Memory Grader output
1 Correct 24 ms 604 KB Ok! 621 queries used.
2 Correct 18 ms 604 KB Ok! 460 queries used.
3 Correct 21 ms 616 KB Ok! 515 queries used.
# Verdict Execution time Memory Grader output
1 Correct 75 ms 868 KB Ok! 1544 queries used.
2 Correct 56 ms 600 KB Ok! 1083 queries used.
3 Correct 72 ms 600 KB Ok! 1530 queries used.
4 Correct 74 ms 600 KB Ok! 1520 queries used.
# Verdict Execution time Memory Grader output
1 Correct 83 ms 604 KB Ok! 1460 queries used.
2 Correct 72 ms 600 KB Ok! 1488 queries used.
3 Correct 71 ms 616 KB Ok! 1488 queries used.
4 Correct 76 ms 616 KB Ok! 1536 queries used.
# Verdict Execution time Memory Grader output
1 Correct 86 ms 604 KB Ok! 1489 queries used.
2 Correct 70 ms 628 KB Ok! 1457 queries used.
3 Correct 80 ms 624 KB Ok! 1352 queries used.
4 Correct 70 ms 604 KB Ok! 1498 queries used.
5 Correct 74 ms 604 KB Ok! 1525 queries used.
6 Correct 72 ms 612 KB Ok! 1534 queries used.
# Verdict Execution time Memory Grader output
1 Correct 73 ms 604 KB Ok! 1450 queries used.
2 Correct 64 ms 612 KB Ok! 1263 queries used.