Submission #988264

# Submission time Handle Problem Language Result Execution time Memory
988264 2024-05-24T11:34:06 Z toan2602 ICC (CEOI16_icc) C++14
100 / 100
86 ms 760 KB
#include<bits/stdc++.h>
#include "icc.h"

using namespace std;

int par[105];
vector<int> node[105];
bool mark[105];
void make_set(int n) {
    for (int i = 1; i <= n; i++) {par[i] = -1; node[i].push_back(i);}
}
int find_anc(int x) {
    if(par[x] < 0) return x;
    return par[x] = find_anc(par[x]);
}

void union_set(int a, int b){
    a = find_anc(a);
    b = find_anc(b);
    if(a != b) {
        if(abs(par[a]) < abs(par[b])) swap(a, b);
        for (int i: node[b]) node[a].push_back(i);
        node[b].clear();
        par[a] += par[b];
        par[b] = a;
    }
}

int ask(int n, int m, vector<int> &a, vector <int> &b)
{
    int A[n], B[m];
    for (int i=0; i<n; i++) A[i]=a[i];
    for (int i=0; i<m; i++) B[i]=b[i];
    return query(n, m, A, B);
}


void run(int n) {
    vector<int> V, a, b, a2, b2;
    make_set(n);
    for (int i = 1; i < n; i++) {
        a.clear();
        b.clear();
        for (int j = 1; j <= n; j++) mark[j] = false;
        V.clear();
        for (int j = 1; j <= n; j++) {
            if(!mark[find_anc(j)]) {
                mark[find_anc(j)] = true;
                V.push_back(find_anc(j));
            }
        }
        int sz = V.size(), mx = __lg(sz);
        for (int j = 0; j <= mx; j++) {
            a.clear();
            b.clear();
            for (int v = 0; v < V.size(); v++) {
                if(v >> j & 1) {
                    for (int dm: node[V[v]]) a.push_back(dm);
                }
                else {
                    for (int dm: node[V[v]]) b.push_back(dm);
                }
            }
            int ans = ask(a.size(), b.size(), a, b);
            if(ans == 1) {
                int sza = a.size(), szb = b.size();
                int l = 0, r = sza - 1, mid;
                while(l != r) {
                    mid = (l + r) / 2;
                    a2.clear();
                    for (int i = l; i <= mid; i++) {
                        a2.push_back(a[i]);
                    }
                    ans = ask(a2.size(), b.size(), a2, b);
                    if(ans == 1) r = mid;
                    else l = mid + 1;
                }
                a2 = {a[l]};
                l = 0, r = szb - 1, mid;
                while(l != r) {
                    mid = (l + r) / 2;
                    b2.clear();
                    for (int i = l; i <= mid; i++) {
                        b2.push_back(b[i]);
                    }
                    ans = ask(1, b2.size(), a2, b2);
                    if(ans == 1) r = mid;
                    else l = mid + 1;
                }
                b2 = {b[l]};
                break;
            }
        }
        setRoad(a2[0], b2[0]);
        union_set(a2[0], b2[0]);
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:56:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             for (int v = 0; v < V.size(); v++) {
      |                             ~~^~~~~~~~~~
icc.cpp:79:40: warning: right operand of comma operator has no effect [-Wunused-value]
   79 |                 l = 0, r = szb - 1, mid;
      |                                        ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Ok! 95 queries used.
2 Correct 4 ms 600 KB Ok! 98 queries used.
# Verdict Execution time Memory Grader output
1 Correct 21 ms 604 KB Ok! 526 queries used.
2 Correct 26 ms 604 KB Ok! 653 queries used.
3 Correct 26 ms 632 KB Ok! 636 queries used.
# Verdict Execution time Memory Grader output
1 Correct 68 ms 604 KB Ok! 1379 queries used.
2 Correct 86 ms 616 KB Ok! 1593 queries used.
3 Correct 79 ms 604 KB Ok! 1593 queries used.
4 Correct 73 ms 600 KB Ok! 1481 queries used.
# Verdict Execution time Memory Grader output
1 Correct 71 ms 620 KB Ok! 1424 queries used.
2 Correct 74 ms 760 KB Ok! 1452 queries used.
3 Correct 78 ms 620 KB Ok! 1575 queries used.
4 Correct 77 ms 616 KB Ok! 1493 queries used.
# Verdict Execution time Memory Grader output
1 Correct 75 ms 600 KB Ok! 1540 queries used.
2 Correct 78 ms 600 KB Ok! 1515 queries used.
3 Correct 78 ms 600 KB Ok! 1573 queries used.
4 Correct 74 ms 624 KB Ok! 1525 queries used.
5 Correct 71 ms 600 KB Ok! 1442 queries used.
6 Correct 75 ms 604 KB Ok! 1478 queries used.
# Verdict Execution time Memory Grader output
1 Correct 75 ms 600 KB Ok! 1538 queries used.
2 Correct 77 ms 600 KB Ok! 1588 queries used.