답안 #1112703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112703 2024-11-14T15:50:29 Z Ghulam_Junaid CEOI16_icc (CEOI16_icc) C++17
90 / 100
93 ms 764 KB
#include <bits/stdc++.h>
#include "icc.h"
// #include "grader.cpp"
using namespace std;

#define all(vv) vv.begin(), vv.end() 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 105;
int n, par[N];
vector<int> S[N];

int root(int v){
    return (par[v] == -1 ? v : par[v] = root(par[v]));
}

void merge(int u, int v){
    if ((u = root(u)) == (v = root(v)))
        return ;

    if (S[u].size() > S[v].size())
        swap(u, v);

    for (int x : S[u]){
        par[x] = v;
        S[v].push_back(x);
    }
    S[u].clear();
}

void run(int nn){
    srand(time(0));

    n = nn;
    for (int i = 1; i <= n; i ++)
        par[i] = -1, S[i] = {i};

    int overall = 0;
    for (int edge = 0; edge < n - 1; edge ++){
        vector<int> roots[2], vec[2];
        set<int> st;
        for (int v = 1; v <= n; v ++)
            st.insert(root(v));
        
        vector<int> all_roots;
        for (int v : st)
            all_roots.push_back(v);

        for (int j : {0, 1})
            roots[j].clear(), vec[j].clear();
        shuffle(all_roots.begin(), all_roots.end(), rng);

        vector<int> sizes = {(int)all_roots.size()};
        while (1){
            for (int j : {0, 1})
                roots[j].clear(), vec[j].clear();
            
            vector<int> new_sizes;
            int i = 0;
            for (int x : sizes){
                if (x == 1){
                    new_sizes.push_back(1);
                    for (int j = i; j < i + 1; j ++)
                        roots[0].push_back(all_roots[j]);
                    i += x;
                }
                else{
                    new_sizes.push_back(x / 2);
                    new_sizes.push_back(x - x / 2);

                    for (int j = i; j < i + x / 2; j ++)
                        roots[0].push_back(all_roots[j]);
                    i += x / 2;

                    for (int j = i; j < i + new_sizes.back(); j ++)
                        roots[1].push_back(all_roots[j]);
                    i += new_sizes.back();
                }
            }
            sizes = new_sizes;

            for (int j : {0, 1})
                for (int x : roots[j])
                    for (int v : S[x])
                        vec[j].push_back(v);

            if (*max_element(all(new_sizes)) == 1)
                break;

            int a[(int)vec[0].size()], b[(int)vec[1].size()];
            copy(all(vec[0]), a), copy(all(vec[1]), b);

            int res = query((int)vec[0].size(), (int)vec[1].size(), a, b);
            if (res) break;
        }

        vector<int> tmp[2] = {vec[0], vec[1]};
        for (int j : {0, 1}){
            int l = -1;
            int r = vec[j].size() - 1;

            while (r - l > 1){
                int mid = (l + r) / 2;

                tmp[j].clear();
                for (int i = 0; i <= mid; i ++)
                    tmp[j].push_back(vec[j][i]);

                int a[(int)tmp[0].size()], b[(int)tmp[1].size()];
                copy(all(tmp[0]), a), copy(all(tmp[1]), b);
                int res = query((int)tmp[0].size(), (int)tmp[1].size(), a, b);
                
                if (res)
                    r = mid;
                else
                    l = mid;

                tmp[j].clear();
                for (int i = l + 1; i <= r; i ++)
                    tmp[j].push_back(vec[j][i]);
            }
            vec[j] = tmp[j];
        }

        setRoad(vec[0][0], vec[1][0]);
        merge(vec[0][0], vec[1][0]);
    }

}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:38:9: warning: unused variable 'overall' [-Wunused-variable]
   38 |     int overall = 0;
      |         ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 592 KB Ok! 99 queries used.
2 Correct 4 ms 648 KB Ok! 102 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 764 KB Ok! 529 queries used.
2 Correct 26 ms 592 KB Ok! 654 queries used.
3 Correct 26 ms 592 KB Ok! 661 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 592 KB Ok! 1461 queries used.
2 Correct 83 ms 592 KB Ok! 1608 queries used.
3 Correct 74 ms 760 KB Ok! 1502 queries used.
4 Correct 88 ms 592 KB Ok! 1531 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 592 KB Ok! 1457 queries used.
2 Correct 76 ms 592 KB Ok! 1511 queries used.
3 Correct 79 ms 592 KB Ok! 1594 queries used.
4 Correct 71 ms 592 KB Ok! 1417 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 592 KB Ok! 1635 queries used.
2 Correct 93 ms 592 KB Ok! 1618 queries used.
3 Correct 83 ms 592 KB Ok! 1638 queries used.
4 Correct 83 ms 592 KB Ok! 1641 queries used.
5 Correct 77 ms 760 KB Ok! 1529 queries used.
6 Correct 83 ms 592 KB Ok! 1624 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 652 KB Ok! 1625 queries used.
2 Incorrect 88 ms 644 KB Too many queries! 1628 out of 1625
3 Halted 0 ms 0 KB -