Submission #580950

# Submission time Handle Problem Language Result Execution time Memory
580950 2022-06-22T06:50:13 Z andrei_boaca ICC (CEOI16_icc) C++14
61 / 100
171 ms 636 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
mt19937_64 rng(time(NULL));
int n;
vector<int> dsu[105];
int comp[105],a[105],b[105],asize,bsize,A[105],X[105],Y[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 p=0;
    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();
            }
        for(int i=1;i<=cnt;i++)
            vals[i]=i;
        if(cnt>20)
        {
            int mid=(cnt+1)/2;
            while(true)
            {
                asize=0;
                for(int i=1;i<=mid;i++)
                    for(int q:dsu[vals[i]])
                        a[asize++]=q;
                bsize=0;
                for(int i=mid+1;i<=cnt;i++)
                    for(int q:dsu[vals[i]])
                        b[bsize++]=q;
                if(query(asize,bsize,a,b))
                    break;
                shuffle(vals+1,vals+cnt+1,rng);
            }
        }
        if(cnt<=20)
        {
            asize=0,bsize=0;
            for(int i=1;i<=cnt;i++)
            {
                int Xsize=0,Ysize=0;
                for(int j:dsu[i])
                    X[Xsize++]=j;
                for(int j=1;j<=cnt;j++)
                    if(j!=i)
                        for(int q:dsu[j])
                            Y[Ysize++]=q;
                if(query(Xsize,Ysize,X,Y))
                {
                    if(asize==0)
                    {
                        for(int j=0;j<Xsize;j++)
                            a[asize++]=X[j];
                    }
                    else
                    {
                        for(int j=0;j<Xsize;j++)
                            b[bsize++]=X[j];
                        break;
                    }
                }
            }
        }
        int st=0;
        int dr=asize-1;
        int x=0;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            /*if(st==dr)
            {
                x=a[mij];
                break;
            }*/
            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;
            /*if(st==dr)
            {
                y=b[mij];
                break;
            }*/
            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);
}*/

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:42:9: warning: unused variable 'p' [-Wunused-variable]
   42 |     int p=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 468 KB Ok! 166 queries used.
2 Correct 8 ms 440 KB Ok! 166 queries used.
# Verdict Execution time Memory Grader output
1 Correct 47 ms 500 KB Ok! 685 queries used.
2 Correct 66 ms 468 KB Ok! 894 queries used.
3 Correct 50 ms 496 KB Ok! 923 queries used.
# Verdict Execution time Memory Grader output
1 Correct 123 ms 520 KB Ok! 1616 queries used.
2 Correct 161 ms 500 KB Ok! 2136 queries used.
3 Correct 160 ms 636 KB Ok! 1836 queries used.
4 Correct 152 ms 512 KB Ok! 1797 queries used.
# Verdict Execution time Memory Grader output
1 Correct 121 ms 508 KB Ok! 1660 queries used.
2 Correct 131 ms 632 KB Ok! 1775 queries used.
3 Correct 171 ms 492 KB Ok! 1932 queries used.
4 Correct 140 ms 508 KB Ok! 1762 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 508 KB Too many queries! 1987 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 500 KB Too many queries! 1979 out of 1625
2 Halted 0 ms 0 KB -