답안 #431760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
431760 2021-06-17T15:08:17 Z AmineWeslati 자동 인형 (IOI18_doll) C++14
53 / 100
233 ms 26628 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define all(x) begin(x),end(x)
#define sz(v) (int)v.size()

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
//------------------------------------------

const int MX=5e5;


int cnt=0; 

vi ans(MX),lft(MX,-1),rgt(MX,-1),par(MX);

int n,root; 
void build(int u, int nb=1){
    if(nb*2>=n) return; 


    lft[u]=++cnt; 
    rgt[u]=++cnt; 
    par[lft[u]]=u; 
    par[rgt[u]]=u; 

    build(lft[u],nb*2);
    build(rgt[u],nb*2);
}


vi st(MX,0);
int last=0;

vi vis_lft(MX,0),vis_rgt(MX,0);

int power(int x){
    bitset<32>b(x);
    int ans=0;
    FOR(i,0,32) ans+=b[i];
    return (ans==1);
}


void dfs(int u, int x){
    st[u]^=1;
    if(st[u]){
        if(lft[u]==-1){
            lft[u]=x; 
            vis_lft[u]=1;
        }
        else{
            dfs(lft[u],x);
        }
    }  
    else{
        if(rgt[u]==-1){
            if(last){
                //cout << u << endl;
                if(u!=cnt){
                    rgt[u]=root; 
                    dfs(root,x);
                }
                else vis_rgt[u]=1,rgt[u]=x; 
            }
            else{
                vis_rgt[u]=1;
                rgt[u]=x; 
            }
        }
        else{
            dfs(rgt[u],x);
        }
    }
    
}

void create_circuit(int M, vi a) {
    int N=sz(a);

    vi adj[M+1];
    adj[0].pb(a[0]);
    FOR(i,0,N){
        if(i==N-1) adj[a[i]].pb(0);
        else adj[a[i]].pb(a[i+1]);
    }


    FOR(i,0,M+1) if(sz(adj[i])){
        n=sz(adj[i]);

        if(n==1){
            ans[i]=adj[i][0];
            continue;
        }

        ++cnt; 
        root=cnt; 
        ans[i]=-root; 
        
        build(root);

        FOR(j,0,n){
            int x=adj[i][j];
            last=(j==n-1);
            dfs(root,x);
        }
    }

    /*FOR(i,1,cnt+1) if(vis_lft[i]){
        cout << lft[i] << ' ' << rgt[i];
        cout << endl;
    }*/

    ans.resize(M+1);
    lft.erase(lft.begin()); lft.resize(cnt); 

    

    FOR(i,0,cnt){
        int &x=lft[i];
        if(!vis_lft[i+1]) x=-x;
    }

    rgt.erase(rgt.begin()); rgt.resize(cnt); 
    FOR(i,0,cnt){
        int &x=rgt[i];
        if(!vis_rgt[i+1]) x=-x;
    }

    /*FOR(i,0,M+1) cout << ans[i] << ' ';
    cout << endl;*/
    /*for(auto x: lft) cout << x << ' ';
    cout << endl;
    for(auto x: rgt) cout << x << ' ';
    cout << endl;*/

    /*for(int x: lft) cout << x << ' ';
    cout << endl; */
    answer(ans,lft,rgt);
}


/*

4 4
1 2 1 3

*/
/*


1 5
1 1 1 1 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13900 KB Output is correct
2 Correct 40 ms 19844 KB Output is correct
3 Correct 34 ms 18772 KB Output is correct
4 Correct 10 ms 13900 KB Output is correct
5 Correct 20 ms 17088 KB Output is correct
6 Correct 62 ms 21316 KB Output is correct
7 Correct 8 ms 13900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13900 KB Output is correct
2 Correct 40 ms 19844 KB Output is correct
3 Correct 34 ms 18772 KB Output is correct
4 Correct 10 ms 13900 KB Output is correct
5 Correct 20 ms 17088 KB Output is correct
6 Correct 62 ms 21316 KB Output is correct
7 Correct 8 ms 13900 KB Output is correct
8 Correct 59 ms 20760 KB Output is correct
9 Correct 78 ms 22112 KB Output is correct
10 Correct 121 ms 24484 KB Output is correct
11 Correct 8 ms 13900 KB Output is correct
12 Correct 8 ms 13900 KB Output is correct
13 Correct 8 ms 13900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13900 KB Output is correct
2 Correct 40 ms 19844 KB Output is correct
3 Correct 34 ms 18772 KB Output is correct
4 Correct 10 ms 13900 KB Output is correct
5 Correct 20 ms 17088 KB Output is correct
6 Correct 62 ms 21316 KB Output is correct
7 Correct 8 ms 13900 KB Output is correct
8 Correct 59 ms 20760 KB Output is correct
9 Correct 78 ms 22112 KB Output is correct
10 Correct 121 ms 24484 KB Output is correct
11 Correct 8 ms 13900 KB Output is correct
12 Correct 8 ms 13900 KB Output is correct
13 Correct 8 ms 13900 KB Output is correct
14 Correct 121 ms 24476 KB Output is correct
15 Correct 58 ms 19524 KB Output is correct
16 Correct 88 ms 22600 KB Output is correct
17 Correct 8 ms 13900 KB Output is correct
18 Correct 8 ms 13900 KB Output is correct
19 Correct 8 ms 14024 KB Output is correct
20 Correct 115 ms 24564 KB Output is correct
21 Correct 9 ms 14080 KB Output is correct
22 Correct 8 ms 14020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 8 ms 13900 KB Output is partially correct
2 Correct 101 ms 18652 KB Output is correct
3 Partially correct 233 ms 20628 KB Output is partially correct
4 Partially correct 178 ms 22044 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 8 ms 13900 KB Output is partially correct
2 Correct 101 ms 18652 KB Output is correct
3 Partially correct 233 ms 20628 KB Output is partially correct
4 Partially correct 178 ms 22044 KB Output is partially correct
5 Partially correct 149 ms 25868 KB Output is partially correct
6 Partially correct 143 ms 26460 KB Output is partially correct
7 Partially correct 131 ms 26248 KB Output is partially correct
8 Partially correct 155 ms 26628 KB Output is partially correct
9 Partially correct 163 ms 20716 KB Output is partially correct
10 Partially correct 215 ms 25448 KB Output is partially correct
11 Partially correct 151 ms 26452 KB Output is partially correct
12 Partially correct 117 ms 22184 KB Output is partially correct
13 Partially correct 91 ms 22028 KB Output is partially correct
14 Partially correct 93 ms 21904 KB Output is partially correct
15 Partially correct 102 ms 21816 KB Output is partially correct
16 Partially correct 10 ms 14156 KB Output is partially correct
17 Partially correct 79 ms 20528 KB Output is partially correct
18 Partially correct 84 ms 20352 KB Output is partially correct
19 Partially correct 93 ms 20888 KB Output is partially correct
20 Partially correct 107 ms 23248 KB Output is partially correct
21 Partially correct 138 ms 24832 KB Output is partially correct
22 Partially correct 110 ms 22536 KB Output is partially correct