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 F first
#define S second
using namespace std;
vector<int> X, Y;
int uni = 12345678;
int Solve(int gd, int bd){
int id = X.size() + 1;
X.pb(0); Y.pb(0);
if(gd + bd == 2){
X[id - 1] = bd ? -1 : uni;
Y[id - 1] = gd ? uni : -1;
return -id;
}
if(gd == 0){
X[id - 1] = -1;
Y[id - 1] = -1;
return -id;
}
int n2 = (gd + bd) / 2;
if(gd <= bd){
X[id - 1] = Solve(0, n2);
Y[id - 1] = Solve(gd, n2 - gd);
} else {
X[id - 1] = Solve(n2 - bd, bd);
Y[id - 1] = Solve(n2, 0);
}
return -id;
}
void create_circuit(int m, vector<int> A) {
X.clear();
Y.clear();
A.pb(0);
// reverse(A.begin(), A.end());
int n = A.size();
int sz = n;
for(int i = 0; i < 30; i++){
if((1 << i) >= n){
sz = (1 << i);
break;
}
}
int rt = Solve(n, sz - n);
int S = X.size();
// cerr << "$ " << S << '\n';
// for(int i = 0; i < S; i++)
// cerr << X[i] << ' ' << Y[i] << '\n';
// cerr << "-----------\n";
vector<int> mk(S, 1);
for(int tri : A){
int nw = -1, nrm;
while(true){
// cerr << "! " << nw << '\n';
nrm = -(nw + 1);
int nx = mk[nrm] ? X[nrm] : Y[nrm];
assert(nx < 0 || nx == uni);
if(nx == uni){
(mk[nrm] ? X[nrm] : Y[nrm]) = tri;
mk[nrm] ^= 1;
break;
} else {
nw = nx;
}
mk[nrm] ^= 1;
}
}
vector<int> C(m + 1, -1);
// cerr << "$ " << S << '\n';
// for(int i = 0; i < S; i++)
// cerr << X[i] << ' ' << Y[i] << '\n';
// cerr << "-----------\n";
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:55:6: warning: unused variable 'rt' [-Wunused-variable]
55 | int rt = Solve(n, sz - n);
| ^~
# | 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... |