Submission #604644

# Submission time Handle Problem Language Result Execution time Memory
604644 2022-07-25T08:21:25 Z BJoozz ICC (CEOI16_icc) C++14
100 / 100
832 ms 612 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define X first
#define Y second
//#define int long long
mt19937 rng(time(0));
bool randint(int l,int r){
    return uniform_int_distribution < int > (l,r) (rng);
}
void maxx(int &a,int b){if(b>a) a=b;}
void minn(int &a,int b){if(b<a) a=b;}
bool cmax(int &a,int b){if(b>a) {a=b;return 1;}return 0;}
using ll = long long;
using ii = pair < int , int >;
const int MAX=100+3,inf=1e9,mod=1e9+7;
//int tim=0,sz[MAX];
bitset < MAX > b,C;
int pa[MAX];
int A[MAX],B[MAX];
bool ok[MAX][MAX];
/*vector < int > V[MAX];
int query ( int n,int m,int a[],int b[]){
    return 1;
}
void setRoad(int u,int v){cout<<u<<' '<<v<<'\n';}*/
void run(int N){
    int n=N;
    vector < int > vec;
    for(int i=1;i<=n;i++) pa[i]=i,vec.pb(i);
    for(int k=1;k<n;k++){
        int cn=0,m=0;

        memset(ok,0,sizeof ok);
        while(1){
            int M=0;
            for(int z=0;z<200;z++){
                for(int i=1;i<=n;i++)b[i]=randint(0,1);
                cn=0;m=0;
                //shuffle(vec.begin(),vec.end(),rng);
                for(int i:vec)if(b[pa[i]])
                A[cn++]=i;else B[m++]=i;
                int dem=0;
                for(int i=0;i<cn;i++)
                for(int j=0;j<m;j++)dem+=!ok[A[i]][B[j]];
                if(cmax(M,dem)) C=b;
            }

            cn=0;m=0;
            shuffle(vec.begin(),vec.end(),rng);
            for(int i:vec)if(C[pa[i]])
            A[cn++]=i;else B[m++]=i;


            if(query(cn,m,A,B))break;
            for(int i=0;i<cn;i++)
            for(int j=0;j<m;j++)
            ok[A[i]][B[j]]=ok[B[j]][A[i]]=1;
        }
        int cnt=cn;cn=0;
        for(int i=0;i<cnt;i++){
            for(int j=0;j<m;j++)
            if(!ok[B[j]][A[i]]){A[cn++]=A[i];break;}
        }

        for(int i=__lg(cn);i>=0;i--)
            if(cn>(1<<i) && query(cn-(1<<i),m,A,B))cn-=(1<<i);

        cnt=m;m=0;
        for(int j=0;j<cnt;j++){
            if(!ok[B[j]][A[cn-1]]){B[m++]=B[j];}
        }
        for(int i=__lg(m);i>=0;i--)
            if(m>(1<<i) && query(cn,m-(1<<i),A,B))m-=(1<<i);
        int u=A[cn-1],v=B[m-1];
        setRoad(u,v);
        u=pa[u];v=pa[v];
        for(int i=1;i<=n;i++) if(pa[i]==v) pa[i]=u;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Ok! 95 queries used.
2 Correct 8 ms 468 KB Ok! 95 queries used.
# Verdict Execution time Memory Grader output
1 Correct 55 ms 504 KB Ok! 526 queries used.
2 Correct 133 ms 488 KB Ok! 463 queries used.
3 Correct 144 ms 612 KB Ok! 487 queries used.
# Verdict Execution time Memory Grader output
1 Correct 341 ms 488 KB Ok! 1259 queries used.
2 Correct 832 ms 496 KB Ok! 1074 queries used.
3 Correct 288 ms 492 KB Ok! 1259 queries used.
4 Correct 553 ms 488 KB Ok! 1281 queries used.
# Verdict Execution time Memory Grader output
1 Correct 407 ms 492 KB Ok! 1245 queries used.
2 Correct 500 ms 492 KB Ok! 1260 queries used.
3 Correct 748 ms 488 KB Ok! 1217 queries used.
4 Correct 274 ms 492 KB Ok! 1261 queries used.
# Verdict Execution time Memory Grader output
1 Correct 749 ms 488 KB Ok! 1204 queries used.
2 Correct 756 ms 488 KB Ok! 1226 queries used.
3 Correct 754 ms 488 KB Ok! 1201 queries used.
4 Correct 684 ms 492 KB Ok! 1258 queries used.
5 Correct 404 ms 492 KB Ok! 1290 queries used.
6 Correct 633 ms 488 KB Ok! 1303 queries used.
# Verdict Execution time Memory Grader output
1 Correct 722 ms 492 KB Ok! 1215 queries used.
2 Correct 819 ms 492 KB Ok! 1121 queries used.