답안 #158586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158586 2019-10-18T03:35:50 Z PeppaPig CEOI16_icc (CEOI16_icc) C++14
100 / 100
169 ms 724 KB
#include "icc.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 105;

int n;
int par[N], a[N], b[N], c[N];
vector<int> C[N];

int find(int x) { while(x != par[x]) x = par[x]; return x; }

void unite(int a, int b) {
    a = find(a), b = find(b);
    if(C[a].size() > C[b].size()) swap(a, b);
    for(int x : C[a]) C[b].emplace_back(x);
    par[a] = b;
}

int solve(int pa, int pb, int a[], int b[]) {
    int l = 0, r = pa-1;
    while(l < r) {
        int mid = (l + r) >> 1;
        int pc = 0;
        for(int i = 0; i <= mid; i++) c[pc++] = a[i];
        if(query(pc, pb, c, b)) r = mid;
        else l = mid + 1;
    }
    return a[r];
}

void run(int _n) {
    n = _n;
    iota(par, par+N, 0);
    for(int i = 1; i <= n; i++) C[i].emplace_back(i);
    for(int road = 1; road < n; road++) {
        vector<int> vec;
        for(int i = 1; i <= n; i++) if(par[i] == i) vec.emplace_back(i);
        for(int bit = 0; bit <= 7; bit++) {
            int pa = 0, pb = 0;
            for(int i = 0; i < vec.size(); i++) {
                if(i >> bit & 1) for(int x : C[vec[i]]) a[pa++] = x;
                else for(int x : C[vec[i]]) b[pb++] = x;
            }
            if(pa == 0 || pb == 0) continue;
            if(query(pa, pb, a, b)) {
                int u = solve(pa, pb, a, b);
                int v = solve(pb, pa, b, a);
                unite(u, v), setRoad(u, v);
                break;
            }
        }
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:42:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < vec.size(); i++) {
                            ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Ok! 99 queries used.
2 Correct 8 ms 632 KB Ok! 94 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 508 KB Ok! 521 queries used.
2 Correct 50 ms 580 KB Ok! 654 queries used.
3 Correct 50 ms 504 KB Ok! 652 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 564 KB Ok! 1419 queries used.
2 Correct 164 ms 632 KB Ok! 1595 queries used.
3 Correct 152 ms 632 KB Ok! 1583 queries used.
4 Correct 152 ms 504 KB Ok! 1514 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 564 KB Ok! 1454 queries used.
2 Correct 154 ms 568 KB Ok! 1584 queries used.
3 Correct 165 ms 504 KB Ok! 1597 queries used.
4 Correct 146 ms 504 KB Ok! 1482 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 500 KB Ok! 1581 queries used.
2 Correct 169 ms 724 KB Ok! 1573 queries used.
3 Correct 163 ms 504 KB Ok! 1606 queries used.
4 Correct 160 ms 560 KB Ok! 1567 queries used.
5 Correct 163 ms 568 KB Ok! 1427 queries used.
6 Correct 152 ms 564 KB Ok! 1523 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 504 KB Ok! 1601 queries used.
2 Correct 164 ms 504 KB Ok! 1611 queries used.