Submission #166880

# Submission time Handle Problem Language Result Execution time Memory
166880 2019-12-04T13:09:44 Z luciocf ICC (CEOI16_icc) C++14
7 / 100
364 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];

int single[maxn], aux[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;

            for (int i = 0; i <= sz_a; i++)
            {
                int ini = 0, fim = sz_b, ans = -1;
                
                single[0] = A[i];

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

                    int sz_aux = -1;

                    for (int j = 0; j <= mid; j++)
                        aux[++sz_aux] = B[j];
                    
                    if (query(1, sz_aux+1, single, aux)) ans = mid, fim = mid-1;
                    else ini = mid+1;
                }

                if (ans != -1) 
                {
                    setRoad(A[i], B[ans]);
                    Join(A[i], B[ans]);
                    break;
                }
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 504 KB Ok! 394 queries used.
2 Correct 27 ms 632 KB Ok! 409 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 344 ms 564 KB Number of queries more than 5000 out of 2500
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 364 ms 564 KB Number of queries more than 4500 out of 2250
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 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 604 KB Number of queries more than 3550 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 253 ms 596 KB Number of queries more than 3250 out of 1625
2 Halted 0 ms 0 KB -