Submission #101818

# Submission time Handle Problem Language Result Execution time Memory
101818 2019-03-20T12:00:29 Z daniel920712 Mechanical Doll (IOI18_doll) C++14
0 / 100
1000 ms 8140 KB
#include "doll.h"
#include <vector>
#include <stdio.h>

using namespace std;
int con[1000005]={0};
int This[1000005]={0};
int m[1000005];
int n[1000005];
int start[1000005]={0};
vector < int > C,x,y;
int X[1000005]={0};
int Y[1000005]={0};
int now=1;
int t[1000005]={0};
void build(int N,int here,int n,int all,int x)
{
    if(n==all-1)
    {
        if(N%2) Y[here]=x;
        else X[here]=x;
    }
    if(N%2)
    {
        if(!Y[here])
        {
            Y[here]=-now;
            now++;
        }
        build(N/2,Y[here],n,all,x);
    }
    else
    {
        if(!X[here])
        {
            X[here]=-now;
            now++;
        }
        build(N/2,X[here],n,all,x);
    }
}
void create_circuit(int M, vector < int > A)
{
    int N=A.size(),i,temp;
    C.push_back(A[0]);
    for(i=1;i<=M;i++) C.push_back(i);
    for(i=0;i<N;i++) con[A[i]]++;
    A.push_back(0);
    for(i=0;i<N;i++)
    {
        if(con[A[i]]==0)
        {
            C[A[i]]=A[i+1];
        }
        else
        {
            if(!This[A[i]])
            {
                C[A[i]]=-now;
                now++;
                t[A[i]]=0;
                temp=1;
                while(temp<con[A[i]])
                {
                    temp*=2;
                    t[A[i]]++;
                }
                start[A[i]]=temp-con[A[i]];
                for(int j=0;j<temp;j++) build(j,C[A[i]],0,t[A[i]],A[i+1]);

            }
            build(This[A[i]]+start[A[i]],C[A[i]],0,t[A[i]],A[i+1]);
            This[A[i]]++;
        }




    }

    //for(auto i:C) printf("%d ",i);
    //printf("\n");
    //for(i=1;i<now;i++) printf("%d %d\n",X[i],Y[i]);
    for(i=1;i<now;i++) x.push_back(X[i]);
    for(i=1;i<now;i++) y.push_back(Y[i]);
    answer(C,x,y);

}
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 8012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 8012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 8012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 8132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 8140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 8140 KB Time limit exceeded
2 Halted 0 ms 0 KB -