답안 #23381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23381 2017-05-08T05:19:19 Z rubabredwan CEOI16_icc (CEOI16_icc) C++14
61 / 100
149 ms 2272 KB
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>
#include "icc.h"

using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> fii;

const int N = 105;

int n, par[N], mat[N][N];
set<int>comp;
vector<int>nudes[N];

int Find(int at){
    return par[at] == at ? at : par[at] = Find(par[at]);
}

void Union(int a, int b){
    int x = Find(a);
    int y = Find(b);
    for(auto u : nudes[y]){
        nudes[x].push_back(u);
    }
    par[y] = x;
    comp.erase(y);
}


 
/* void setRoad(int a, int b){ */
/*     if(a) Union(a, b); */
/*     int x, y; */
/*     cin >> x >> y; */
/*     mat[x][y] = 1; */
/*     mat[y][x] = 1; */
/* } */
 
/* int query(int sa, int sb, int a[], int b[]){ */
/*     for(int i=0;i<sa;i++){ */
/*         for(int j=0;j<sb;j++){ */
/*             if(mat[a[i]][b[j]]) return true; */
/*         } */
/*     } */
/*     return false; */
/* } */
 

int bs[N], tt;

int get(int sa, int sb, int a[], int b[]){
    int lo = 0, hi = sb - 1;
    while(lo < hi){
        int mid = (lo + hi) / 2; tt = 0;
        for(int i=lo;i<=mid;i++) bs[tt] = b[i], ++tt;
        if(query(sa, tt, a, bs)) hi = mid;
        else lo = mid + 1;
    }
    return b[lo];
}

int aa[N], bb[N];
int sa, sb;
vector<int>vv[10][2];

void run(int _n){
    srand(time(NULL));
    n = _n;
    comp.clear();
    for(int i=1;i<=n;i++){
        par[i] = i;
        comp.insert(i);
        nudes[i].push_back(i);
    }
    int road = n - 1;
    while(road--){
        int f1 = 0, f2 = 0;
        vector<fii>F;
        for(int bit=7;bit>=0;bit--){
            vv[bit][0].clear();
            vv[bit][1].clear();
            for(auto u : comp){
                if(u & (1 << bit)) for(auto v : nudes[u]) vv[bit][0].push_back(v);
                else for(auto v : nudes[u]) vv[bit][1].push_back(v);
            }
            if(vv[bit][0].size() == 0) continue;
            if(vv[bit][1].size() == 0) continue;
            if(query(vv[bit][0].size(), vv[bit][1].size(), vv[bit][0].data(), vv[bit][1].data())){
                F.push_back({{vv[bit][0].size(), bit}, 0});
                F.push_back({{vv[bit][1].size(), bit}, 1});
                //break;
            }
        }
        sort(F.begin(), F.end());
        for(auto u : F){
            int b = u.first.second, t = u.second;
            if(find(vv[b][t].begin(), vv[b][t].end(), f1) != vv[b][t].end()) continue;
            if(find(vv[b][t].begin(), vv[b][t].end(), f2) != vv[b][t].end()) continue;
            if(!f1){
                f1 = get(vv[b][t^1].size(), vv[b][t].size(), vv[b][t^1].data(), vv[b][t].data());
            }
            else if(!f2){
                f2 = get(vv[b][t^1].size(), vv[b][t].size(), vv[b][t^1].data(), vv[b][t].data());
            }
        }
        assert(f1);
        assert(f2);
        Union(f1, f2);
        setRoad(f1, f2);
    }
}

/* int main(){ */
/*     int ff, x, y; */
/*     scanf("%d", &ff); */
/*     setRoad(0, 0); */
/*     run(ff); */
/*     return 0; */
/* } */
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2140 KB Ok! 122 queries used.
2 Correct 6 ms 2140 KB Ok! 127 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 2272 KB Ok! 672 queries used.
2 Correct 49 ms 2136 KB Ok! 748 queries used.
3 Correct 46 ms 2268 KB Ok! 741 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 2268 KB Ok! 1738 queries used.
2 Correct 149 ms 2268 KB Ok! 1820 queries used.
3 Correct 139 ms 2272 KB Ok! 1667 queries used.
4 Correct 143 ms 2272 KB Ok! 1761 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 2272 KB Ok! 1729 queries used.
2 Correct 143 ms 2272 KB Ok! 1739 queries used.
3 Correct 146 ms 2268 KB Ok! 1791 queries used.
4 Correct 143 ms 2268 KB Ok! 1754 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 143 ms 2268 KB Too many queries! 1786 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 149 ms 2272 KB Too many queries! 1835 out of 1625
2 Halted 0 ms 0 KB -