Submission #581198

# Submission time Handle Problem Language Result Execution time Memory
581198 2022-06-22T11:09:08 Z andrei_boaca ICC (CEOI16_icc) C++14
100 / 100
136 ms 632 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
mt19937 rng(time(NULL));
int n;
vector<int> dsu[105];
int comp[105],a[105],b[105],asize,bsize,A[105];
int comps[105][105],vals[105];
void dsu_merge(int c1,int c2)
{
    if(dsu[c1].size()<dsu[c2].size())
        swap(c1,c2);
    for(int i:dsu[c2])
    {
        comp[i]=c1;
        dsu[c1].push_back(i);
    }
    dsu[c2].clear();
}
int adj[105][105];
/*int query(int asize,int bsize, int v[105],int w[105])
{
    for(int i=0;i<asize;i++)
        for(int j=0;j<bsize;j++)
            if(adj[v[i]][w[j]])
                return 1;
    return 0;
}
void setRoad(int x,int y)
{
    cout<<x<<' '<<y<<'\n';
    adj[x][y]=adj[y][x]=1;
}*/
void run(int N)
{
    n=N;
    for(int i=1;i<=n;i++)
    {
        dsu[i].push_back(i);
        comp[i]=i;
    }
    int nr=n;
    for(int z=1;z<n;z++,nr--)
    {
        int cnt=0;
        /*int h,e;
        cin>>h>>e;
        adj[h][e]=adj[e][h]=1;*/
        for(int i=1;i<=n;i++)
            if(dsu[i].size())
            {
                cnt++;
                for(int j:dsu[i])
                    comp[j]=cnt;
                dsu[cnt]=dsu[i];
                if(i!=cnt)
                    dsu[i].clear();
            }
        int bitlim=0;
        for(int i=1;i<=cnt;i++)
        {
            vals[i]=i;
            for(int bit=0;bit<7;bit++)
                if((i>>bit)&1)
                    bitlim=max(bitlim,bit);
        }
        for(int bit=0;bit<=bitlim;bit++)
        {
            asize=0,bsize=0;
            for(int i=1;i<=cnt;i++)
            {
                if((i>>bit)&1)
                    {
                        for(int j:dsu[i])
                            a[asize++]=j;
                    }
                else
                {
                    for(int j:dsu[i])
                        b[bsize++]=j;
                }
            }
            if(bit==bitlim||query(asize,bsize,a,b))
                break;
        }
        int st=0;
        int dr=asize-1;
        int x=0;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            int sza=0;
            for(int i=0;i<=mij;i++)
                A[sza++]=a[i];
            int ans=query(sza,bsize,A,b);
            if(ans==1)
            {
                x=a[mij];
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        st=0;
        dr=bsize-1;
        int y=0;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            int sza=0;
            for(int i=0;i<=mij;i++)
                A[sza++]=b[i];
            int ans=query(sza,asize,A,a);
            if(ans==1)
            {
                y=b[mij];
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        dsu_merge(comp[x],comp[y]);
        setRoad(x,y);
    }
}
/*int main()
{
    int N;
    cin>>N;
    run(N);
}*/
# Verdict Execution time Memory Grader output
1 Correct 7 ms 468 KB Ok! 104 queries used.
2 Correct 6 ms 508 KB Ok! 102 queries used.
# Verdict Execution time Memory Grader output
1 Correct 32 ms 468 KB Ok! 541 queries used.
2 Correct 47 ms 504 KB Ok! 649 queries used.
3 Correct 36 ms 508 KB Ok! 650 queries used.
# Verdict Execution time Memory Grader output
1 Correct 123 ms 632 KB Ok! 1488 queries used.
2 Correct 136 ms 516 KB Ok! 1617 queries used.
3 Correct 121 ms 488 KB Ok! 1560 queries used.
4 Correct 127 ms 588 KB Ok! 1511 queries used.
# Verdict Execution time Memory Grader output
1 Correct 126 ms 604 KB Ok! 1564 queries used.
2 Correct 122 ms 496 KB Ok! 1572 queries used.
3 Correct 129 ms 508 KB Ok! 1612 queries used.
4 Correct 121 ms 528 KB Ok! 1542 queries used.
# Verdict Execution time Memory Grader output
1 Correct 125 ms 468 KB Ok! 1582 queries used.
2 Correct 121 ms 516 KB Ok! 1612 queries used.
3 Correct 135 ms 520 KB Ok! 1611 queries used.
4 Correct 125 ms 496 KB Ok! 1605 queries used.
5 Correct 129 ms 516 KB Ok! 1525 queries used.
6 Correct 123 ms 468 KB Ok! 1568 queries used.
# Verdict Execution time Memory Grader output
1 Correct 124 ms 512 KB Ok! 1612 queries used.
2 Correct 127 ms 512 KB Ok! 1612 queries used.