답안 #984691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984691 2024-05-17T02:50:27 Z Maaxle CEOI16_icc (CEOI16_icc) C++17
100 / 100
88 ms 848 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()){
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 600 KB Ok! 112 queries used.
2 Correct 4 ms 604 KB Ok! 110 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 636 KB Ok! 621 queries used.
2 Correct 25 ms 604 KB Ok! 460 queries used.
3 Correct 27 ms 604 KB Ok! 515 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 600 KB Ok! 1544 queries used.
2 Correct 55 ms 600 KB Ok! 1083 queries used.
3 Correct 71 ms 600 KB Ok! 1530 queries used.
4 Correct 73 ms 600 KB Ok! 1520 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 612 KB Ok! 1460 queries used.
2 Correct 71 ms 604 KB Ok! 1488 queries used.
3 Correct 72 ms 640 KB Ok! 1488 queries used.
4 Correct 74 ms 600 KB Ok! 1536 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 600 KB Ok! 1489 queries used.
2 Correct 84 ms 848 KB Ok! 1457 queries used.
3 Correct 68 ms 604 KB Ok! 1352 queries used.
4 Correct 74 ms 600 KB Ok! 1498 queries used.
5 Correct 73 ms 604 KB Ok! 1525 queries used.
6 Correct 82 ms 848 KB Ok! 1534 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 600 KB Ok! 1450 queries used.
2 Correct 63 ms 604 KB Ok! 1263 queries used.