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>
using namespace std;
int S = 0;
vector<int> X, Y;
vector<int> state;
int build(int n, int h){
if(h == 0) return 1;
int ind = S++;
X.resize(S);
Y.resize(S);
int k = (1<<(h-1));
vector<int> le, ri;
// cerr << n << " " << k << "\n";
Y[ind] = build(min(k, n), h-1);
if(k >= n){
X[ind] = -1; // root
}
else{
X[ind] = build(n-k, h-1);
}
return -(ind+1);
}
int exec(){
int i = -1;
while(true){
int j = -i-1;
if(state[j]) i = Y[j];
else i = X[j];
state[j] ^= 1;
if(i == 1) return j;
if(i == -1) return -1;
}
}
void create_circuit(int M, vector<int> A) {
A.push_back(0);
int n = (int)A.size();
int h = (int)ceil(log2(n));
build(n, h);
state.resize(S);
int i = 0;
while(i < n){
int j = exec();
if(j > 0){
if(state[j]) X[j] = A[i++];
else Y[j] = A[i++];
}
}
vector<int> C(M + 1, -1);
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... |