Submission #166889

# Submission time Handle Problem Language Result Execution time Memory
166889 2019-12-04T13:25:11 Z luciocf ICC (CEOI16_icc) C++14
18 / 100
389 ms 632 KB
#include <bits/stdc++.h>
#include "icc.h"

using namespace std;

const int maxn = 110;

int pai[maxn], peso[maxn];
int A[maxn], B[maxn];

vector<int> comp[maxn];

void init(int n)
{
    for (int i = 1; i <= n; i++)
    {
        pai[i] = i, peso[i] = 1;
        comp[i].push_back(i);
    }
}

int Find(int x)
{
    if (pai[x] == x) return x;
    return pai[x] = Find(pai[x]);
}

void Join(int x, int y)
{
    x = Find(x), y = Find(y);
    if (x == y) return;

    if (peso[x] < peso[y]) swap(x, y);

    pai[y] = x, peso[x] += peso[y];

    for (auto v: comp[y])
        comp[x].push_back(v);
}

void run(int n)
{
    init(n);
    
    for (int e = 1; e < n; e++)
    {
        for (int b = 0; b < 7; b++)
        {
            int sz_a = -1, sz_b = -1;

            for (int i = 1; i <= n; i++)
            {
                if (Find(i) == i)
                {
                    if (i&(1<<b))
                    {
                        for (auto v: comp[i])
                            A[++sz_a] = v;
                    }
                    else
                    {
                        for (auto v: comp[i])
                            B[++sz_b] = v;
                    }
                }
            }

            if (!query(sz_a+1, sz_b+1, A, B)) continue;

            int ini = 0, fim = sz_a, ans = -1;

            while (ini <= fim)
            {
                int mid = (ini+fim)>>1;

                int ini2 = 0, fim2 = sz_b, ans2 = -1;

                while (ini2 <= fim2)
                {
                    int mid2 = (ini2+fim2)>>1;
                    
                    if (query(mid+1, mid2+1, A, B)) ans2 = mid2, fim2 = mid2-1;
                    else ini2 = mid2+1;
                }

                if (ans2 != -1) ans = mid, fim = mid-1;
                else ini = mid+1;
            }

            int ini2 = 0, fim2 = sz_b, ans2 = -1;

            while (ini2 <= fim2)
            {
                int mid2 = (ini2+fim2)>>1;
                
                if (query(ans+1, mid2+1, A, B)) ans2 = mid2, fim2 = mid2-1;
                else ini2 = mid2+1;
            }

            setRoad(A[ans], B[ans2]);
            Join(A[ans], B[ans2]);

            break;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 504 KB Ok! 190 queries used.
2 Correct 14 ms 632 KB Ok! 191 queries used.
# Verdict Execution time Memory Grader output
1 Correct 101 ms 632 KB Ok! 1374 queries used.
2 Correct 113 ms 504 KB Ok! 1579 queries used.
3 Correct 115 ms 604 KB Ok! 1608 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 389 ms 504 KB Too many queries! 4085 out of 2250
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 374 ms 504 KB Number of queries more than 4000 out of 2000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 325 ms 568 KB Number of queries more than 3550 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 304 ms 564 KB Number of queries more than 3250 out of 1625
2 Halted 0 ms 0 KB -