Submission #911691

# Submission time Handle Problem Language Result Execution time Memory
911691 2024-01-19T04:44:11 Z biank Mechanical Doll (IOI18_doll) C++14
0 / 100
1000 ms 348 KB
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
#define SIZE(x) (int)x.size()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define pb push_back
typedef vector<int> vi;

vi L, R, v, state;
int t=1, skip, s=-1;

void build(int u, int l, int r) {
    L.pb(0), R.pb(0), v.pb(0);
    if(r-l<=skip) {
        v[u]=-1, skip-=r-l;
        return;
    }
    if(r-l==1) return;
    v[u]=s--;
    int m=(l+r)/2;
    L[u]=t++, R[u]=t++;
    build(L[u],l,m);
    build(R[u],m,r);
}
     
void dfs(int u, int a) {
    if(u && v[u]==-1) dfs(0,a);
    else if(!v[u]) v[u]=a;
    else if(state[u]^=1) dfs(L[u],a);
    else return dfs(R[u],a);
}
     
void create_circuit(int m, vi a) {
    vi c(m+1,0), x, y;
    c[0]=a[0];
    int n=SIZE(a);
    if(n==1) {
        answer(c,x,y);
        return;
    }
    forsn(i,1,m+1) c[i]=-1;
    int sz=1;
    while(sz<n) sz*=2;
    skip=sz-n;
    build(0,0,sz);
    a.pb(0);
    state.assign(SIZE(v),0);
    forsn(i,1,n+1) dfs(0,a[i]);
    forn(i,t) {
        if(L[i] || R[i]) x.pb(v[L[i]]), y.pb(v[R[i]]);
    }
    answer(c,x,y);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -