답안 #52033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52033 2018-06-23T10:10:39 Z someone_aa CEOI16_icc (CEOI16_icc) C++17
90 / 100
225 ms 976 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;

const int maxn = 110;
int parent[maxn];

vector<int>comps[maxn];

/*bool query(int a, int b, int aa[], int bb[]) {
    for(int i=0;i<a;i++) {
        cout<<aa[i]<<" ";
    } cout<<"\n";
    for(int i=0;i<b;i++) {
        cout<<bb[i]<<" ";
    } cout<<"\n";

    bool answ;
    cin>>answ;
    return answ;
}

void setRoad(int x, int y) {
    cout<<"Road: "<<x<<" "<<y<<"\n";
}*/

int uroot(int x) {
    while(x != parent[x]) x = parent[x];
    return x;
}

void unite(int x, int y) {
    x = uroot(x);
    y = uroot(y);

    if(x==y) return;
    for(int i:comps[x]) {
        comps[y].push_back(i);
    }
    parent[x] = y;
}

bool qq(set<int>a, set<int> b) {
    int aa[a.size()], bb[b.size()];
    int br = 0;
    for(int i:a) aa[br++] = i;
    br = 0;
    for(int i:b) bb[br++] = i;
    return query(a.size(), b.size(), aa, bb);
}

int bin(set<int>a, set<int>b) {
    if(b.size() == 1) {
        return (*(b.begin()));
    }

    set<int>fi, si;
    int br = 0;

    for(int i:b) {
        if(br < (b.size()/2)) fi.insert(i);
        else si.insert(i);
        br++;
    }
    
    if(qq(a, si)) return bin(a, si);
    else return bin(a, fi);
}

void run(int n) {
    set<int>c;

    for(int i=1;i<=n;i++) {
        parent[i] = i;
        comps[i].push_back(i);
    }

    for(int edges=1;edges<n;edges++) {
        for(int i=1;i<=n;i++) {
            c.insert(uroot(i));
        }

        for(int i=6;i>=0;i--) {
            set<int>a, b;
            for(int j:c) {
                if(j&(1<<i)) for(int k:comps[j]) a.insert(k);
                else for(int k:comps[j]) b.insert(k);
            }

            if(a.size() > 0 && b.size() > 0) {
                if(qq(a, b)) {
                    int x = bin(a, b);
                    int y = bin(b, a);
                    setRoad(x, y);
                    unite(x, y);
                    break;
                }
            }
        }
        c.clear();
    }
}

/*int main() {
    run(4);
    return 0;
}*/

Compilation message

icc.cpp: In function 'int bin(std::set<int>, std::set<int>)':
icc.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(br < (b.size()/2)) fi.insert(i);
            ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 508 KB Ok! 101 queries used.
2 Correct 9 ms 612 KB Ok! 98 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 688 KB Ok! 558 queries used.
2 Correct 54 ms 688 KB Ok! 661 queries used.
3 Correct 63 ms 792 KB Ok! 651 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 816 KB Ok! 1441 queries used.
2 Correct 225 ms 852 KB Ok! 1631 queries used.
3 Correct 179 ms 976 KB Ok! 1589 queries used.
4 Correct 175 ms 976 KB Ok! 1555 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 976 KB Ok! 1515 queries used.
2 Correct 173 ms 976 KB Ok! 1530 queries used.
3 Correct 172 ms 976 KB Ok! 1575 queries used.
4 Correct 157 ms 976 KB Ok! 1434 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 976 KB Ok! 1565 queries used.
2 Correct 177 ms 976 KB Ok! 1618 queries used.
3 Correct 179 ms 976 KB Ok! 1642 queries used.
4 Correct 185 ms 976 KB Ok! 1644 queries used.
5 Correct 190 ms 976 KB Ok! 1571 queries used.
6 Correct 214 ms 976 KB Ok! 1673 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 976 KB Ok! 1614 queries used.
2 Incorrect 181 ms 976 KB Too many queries! 1639 out of 1625