Submission #919248

# Submission time Handle Problem Language Result Execution time Memory
919248 2024-01-31T13:27:59 Z vjudge1 ICC (CEOI16_icc) C++17
90 / 100
91 ms 852 KB
#include <bits/stdc++.h>
#include "icc.h"

// author: aykhn

using namespace std;

struct DSU
{
    vector<vector<int>> id;
    vector<int> e;
    void init(int n)
    {
        id.resize(n + 1);
        for (int i = 1; i <= n; i++) id[i].push_back(i);
        e.assign(n + 1, -1);
    }
    int get(int x)
    {
        if (e[x] < 0) return x;
        return e[x] = get(e[x]);
    }
    void unite(int x, int y)
    {
        x = get(x), y = get(y);
        if (x == y) return;
        if (e[x] > e[y]) swap(x, y);
        for (int z : id[y]) id[x].push_back(z);
        id[y].clear();
        e[x] += e[y];
        e[y] = x;
    }
};

void run(int n)
{
    srand(time(0));
    DSU dsu;
    dsu.init(n);
    for (int C = 1; C < n; C++)
    {
        vector<int> v;
        for (int i = 1; i <= n; i++) if (dsu.get(i) == i) v.push_back(i);
        random_shuffle(v.begin(), v.end());
        int val = 0;
        vector<int> a[2];
        for (int lg = 0; lg < 7; lg++)
        {
            a[0].clear(), a[1].clear();
            for (int i = 0; i < v.size(); i++)
            {
                for (int z : dsu.id[v[i]]) a[i >> lg & 1].push_back(z);
            }
            if (query(a[0].size(), a[1].size(), a[0].data(), a[1].data())) break;
        }
        int l = 0;
        int r = (int)a[0].size() - 1;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            vector<int> x, y;
            for (int i = l; i <= mid; i++) x.push_back(a[0][i]);
            for (int i = mid + 1; i <= r; i++) y.push_back(a[0][i]);
            if (query(a[1].size(), x.size(), a[1].data(), x.data()))
            {
                a[0] = x;
                r = mid;
            }
            else
            {
                a[0] = y;
                l = mid + 1;
            }
        }
        l = 0;
        r = (int)a[1].size() - 1;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            vector<int> x, y;
            for (int i = l; i <= mid; i++) x.push_back(a[1][i]);
            for (int i = mid + 1; i <= r; i++) y.push_back(a[1][i]);
            if (query(a[0].size(), x.size(), a[0].data(), x.data()))
            {
                a[1] = x;
                r = mid;
            }
            else
            {
                a[1] = y;
                l = mid + 1;
            }
        }
        dsu.unite(a[0][0], a[1][0]);
        setRoad(a[0][0], a[1][0]);
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:50:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             for (int i = 0; i < v.size(); i++)
      |                             ~~^~~~~~~~~~
icc.cpp:45:13: warning: unused variable 'val' [-Wunused-variable]
   45 |         int val = 0;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Ok! 101 queries used.
2 Correct 4 ms 600 KB Ok! 97 queries used.
# Verdict Execution time Memory Grader output
1 Correct 23 ms 600 KB Ok! 511 queries used.
2 Correct 28 ms 600 KB Ok! 646 queries used.
3 Correct 28 ms 604 KB Ok! 647 queries used.
# Verdict Execution time Memory Grader output
1 Correct 73 ms 600 KB Ok! 1408 queries used.
2 Correct 87 ms 620 KB Ok! 1622 queries used.
3 Correct 85 ms 600 KB Ok! 1610 queries used.
4 Correct 78 ms 600 KB Ok! 1489 queries used.
# Verdict Execution time Memory Grader output
1 Correct 80 ms 852 KB Ok! 1493 queries used.
2 Correct 79 ms 600 KB Ok! 1518 queries used.
3 Correct 85 ms 760 KB Ok! 1624 queries used.
4 Correct 77 ms 600 KB Ok! 1459 queries used.
# Verdict Execution time Memory Grader output
1 Correct 87 ms 628 KB Ok! 1597 queries used.
2 Correct 86 ms 600 KB Ok! 1592 queries used.
3 Correct 87 ms 616 KB Ok! 1635 queries used.
4 Correct 86 ms 604 KB Ok! 1605 queries used.
5 Correct 78 ms 616 KB Ok! 1474 queries used.
6 Correct 91 ms 616 KB Ok! 1547 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 620 KB Too many queries! 1627 out of 1625
2 Halted 0 ms 0 KB -