답안 #759109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759109 2023-06-15T18:54:25 Z alexander707070 자동 인형 (IOI18_doll) C++14
2 / 100
39 ms 24668 KB
#include<bits/stdc++.h>
#include "doll.h"
#define MAXN 800007
using namespace std;

int m,power,n,sz,curr,root;
int a[MAXN],s;
int lt[MAXN],rt[MAXN];
vector<int> from,to,c,w[MAXN];

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,int num,int id){
    if(l+1==r){
        num*=2;
        if(rev(num)<sz-1)lt[v]=w[id][rev(num)];
        else if(rev(num)==power-1)lt[v]=w[id].back();
        else lt[v]=root;

        num++;
        if(rev(num)<sz-1)rt[v]=w[id][rev(num)];
        else if(rev(num)==power-1)rt[v]=w[id].back();
        else rt[v]=root;

    }else{
        int tt=(l+r)/2;
        curr++; lt[v]=-curr;
        build(curr,l,tt,2*num,id);
        curr++; rt[v]=-curr;
        build(curr,tt+1,r,2*num+1,id);
    }
}

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];
    }

    for(int i=0;i<n;i++){
        w[a[i]].push_back(a[i+1]);
    }

    for(int i=0;i<=m;i++)c.push_back(-1);
    c[0]=a[0]; curr=1;

    for(int i=1;i<=m;i++){
        if(w[i].empty())continue;

        if(w[i].size()==1){
            c[i]=w[i][0]; continue;
        }

        sz=w[i].size(); power=1;
        while(power<sz)power*=2;

        root=curr;
        build(curr,0,power-1,0,i);
    }

    for(int i=1;i<=curr;i++){
        from.push_back(lt[i]);
        to.push_back(rt[i]);
    }

    answer(c,from,to);
}

/*
int main(){
     create_circuit(4, {1,2,1,3});
}
*/




# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18992 KB Output is correct
2 Correct 39 ms 23144 KB Output is correct
3 Correct 26 ms 22752 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 19 ms 20300 KB Output is correct
6 Correct 36 ms 24668 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18992 KB Output is correct
2 Correct 39 ms 23144 KB Output is correct
3 Correct 26 ms 22752 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 19 ms 20300 KB Output is correct
6 Correct 36 ms 24668 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
8 Incorrect 35 ms 23412 KB wrong motion
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18992 KB Output is correct
2 Correct 39 ms 23144 KB Output is correct
3 Correct 26 ms 22752 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 19 ms 20300 KB Output is correct
6 Correct 36 ms 24668 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
8 Incorrect 35 ms 23412 KB wrong motion
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB wrong serial number
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19032 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19032 KB wrong motion
2 Halted 0 ms 0 KB -