This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int inf = 1e9;
int P = 0, SZ = 0;
vector<int> state;
int gen_switch(int N, int to_kill, int &S, vector<int> &X, vector<int> &Y) {
if(N == to_kill) return inf;
if(N == 1) return inf + 1;
int L, R;
if(to_kill <= (N >> 1)) {
L = gen_switch(N >> 1, to_kill, S, X, Y);
R = gen_switch(N >> 1, 0, S, X, Y);
} else {
L = inf;
R = gen_switch(N >> 1, to_kill - (N >> 1), S, X, Y);
}
int root = --S;
X.pb(L), Y.pb(R), state.pb(0);
return root;
}
int simulate(int root, int x, vector<int> &A, vector<int> &X, vector<int> &Y) {
if(x == inf + 1) return A[P++];
int pos = -x - 1;
if(state[pos] == 0 && X[pos] != root)
X[pos] = simulate(root, X[pos], A, X, Y);
if(state[pos] == 1 && Y[pos] != root)
Y[pos] = simulate(root, Y[pos], A, X, Y);
state[pos] ^= 1;
return x;
}
void create_circuit(int M, vector<int> A) {
A.pb(0);
int S = 0, N = (int)A.size();
int pot = 1, K = 0;
while(pot < N) pot <<= 1, K++;
vector<int> C, X, Y;
int root = gen_switch(pot, pot - N, S, X, Y);
for(int i = 0;i < abs(S);i++) {
if(X[i] == inf) X[i] = root;
if(Y[i] == inf) Y[i] = root;
}
C = vector<int>(M + 1, root);
while(P < N)
simulate(root, root, A, X, Y);
answer(C, X, Y);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |