Submission #760831

# Submission time Handle Problem Language Result Execution time Memory
760831 2023-06-18T16:20:23 Z alexander707070 Mechanical Doll (IOI18_doll) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
#include "doll.h"
#define MAXN 800007
using namespace std;
 
int m,power,n,num;
int a[MAXN],s,ind[MAXN],temp[MAXN];
int lt[MAXN],rt[MAXN];
vector<int> from,to,c;

int rev(int x){
    int res=0;
    for(int i=1;i<power;i*=2){
        res*=2; res+=x%2; 
        x/=2;
    }
    return res;
}
 
void build(int v,int l,int r){
    if(l>n){
        lt[v]=rt[v]=-1;
        return;
    }

    if(l+1==r){
        if(l<n)lt[v]=a[l];
        else if(l==n)lt[v]=0;
        else lt[v]=-1;

        if(r<n)rt[v]=a[r];
        else if(r==n)rt[v]=0;
        else rt[v]=-1;
    }else{
        int tt=(l+r)/2;
        num++; lt[v]=-num;
        build(num,l,tt);
        num++; rt[v]=-num;
        build(num,tt+1,r);
    }
}

bool cmp(int x,int y){
    return rev(x)<rev(y);
}
 
void create_circuit(int M, vector<int> A){
    m=M; n=int(A.size());
 
    for(int i=0;i<n;i++){
        a[i]=A[i]; ind[i]=i;
    }

    power=1; num=1;
    while(power<n+1)power*=2;

    sort(ind,ind+n,cmp);

    for(int i=0;i<n;i++)temp[ind[i]]=a[i];
    for(int i=0;i<n;i++)a[i]=temp[i];

    build(1,0,power-1);
 
    for(int i=0;i<=m;i++)c.push_back(-1);
 
    for(int i=1;i<=num;i++){
        from.push_back(lt[i]);
        to.push_back(rt[i]);
    }
    answer(c,from,to);
}
 
/*
int main(){
     create_circuit(4, {1, 2, 1,3,2,4,3,1,2});
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB wrong motion
2 Halted 0 ms 0 KB -