답안 #1112634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112634 2024-11-14T13:03:50 Z Ghulam_Junaid CEOI16_icc (CEOI16_icc) C++17
40 / 100
114 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){
    n = nn;
    for (int i = 1; i <= n; i ++)
        par[i] = -1, S[i] = {i};

    for (int edge = 0; edge < n - 1; edge ++){
        vector<int> roots[2], vec[2];
        while (1){
            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);
            for (int i = 0; i < all_roots.size(); i ++){
                int id = (i >= all_roots.size() / 2);
                roots[id].push_back(all_roots[i]);
                for (int v : S[all_roots[i]])
                    vec[id].push_back(v);
            }

            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;
        }

        for (int j : {0, 1}){
            int l = -1;
            int r = roots[j].size() - 1;

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

                vec[j].clear();
                for (int i = 0; i <= mid; i ++)
                    for (int v : S[roots[j][i]])
                        vec[j].push_back(v);

                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)
                    r = mid;
                else
                    l = mid;

                vec[j].clear();
                for (int i = l + 1; i <= r; i ++)
                    for (int v : S[roots[j][i]])
                        vec[j].push_back(v);

            }
            int imp = roots[j][r];
            roots[j] = {imp};
        }

        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:51:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for (int i = 0; i < all_roots.size(); i ++){
      |                             ~~^~~~~~~~~~~~~~~~~~
icc.cpp:52:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 int id = (i >= all_roots.size() / 2);
      |                           ~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 592 KB Ok! 111 queries used.
2 Correct 5 ms 592 KB Ok! 115 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 592 KB Ok! 671 queries used.
2 Correct 36 ms 592 KB Ok! 830 queries used.
3 Correct 39 ms 764 KB Ok! 828 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 640 KB Ok! 1844 queries used.
2 Correct 114 ms 592 KB Ok! 2099 queries used.
3 Correct 110 ms 644 KB Ok! 2058 queries used.
4 Correct 104 ms 592 KB Ok! 2028 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 106 ms 764 KB Too many queries! 2069 out of 2000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 113 ms 644 KB Too many queries! 2067 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 110 ms 636 KB Too many queries! 2101 out of 1625
2 Halted 0 ms 0 KB -