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 n, m;
vector<int> x, y;
int t = 0;
void make(int n, int f) {
if (f == 2) {
if (n == 2) {
x.push_back(0);
y.push_back(0);
}
else {
x.push_back(-1);
y.push_back(0);
}
t++;
return;
}
if (n <= f/2) {
x.push_back(-1);
t++;
y.push_back(-t);
make(n, f/2);
}
else {
t++;
int l_size = n-f/2;
x.push_back(-t);
y.push_back(0);
int uv = y.size()-1;
make(l_size, f/2);
y[uv] = -t;
make(f/2, f/2);
}
return;
}
vector<int> state;
void sim(int cur, int tar) {
int nxt;
if (state[cur] == 0) {
nxt = -x[cur-1];
}
else nxt = -y[cur-1];
if (nxt == 0) {
if (state[cur] == 0) x[cur-1] = tar;
else y[cur-1] = tar;
}
state[cur] = 1-state[cur];
if (nxt != 0) sim(nxt, tar);
}
void create_circuit(int M, vector<int> A) {
n = A.size();
m = M;
vector<int> C(M + 1);
fill(C.begin(), C.end(), -1);
C[0] = A[0];
vector<int> nvals;
for (int i = 1; i < n; i++) nvals.push_back(A[i]);
nvals.push_back(0);
int f = 1;
while (f < n) f *= 2; t++;
make(n, f);
state = vector<int>(t);
fill(state.begin(), state.end(), 0);
for (int i = 0; i < n; i++) sim(1, nvals[i]);
answer(C, x, y);
// for (int i = 0; i < x.size(); i++) cout << x[i] << ' ' << y[i] << "\n";
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:70:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
70 | while (f < n) f *= 2; t++;
| ^~~~~
doll.cpp:70:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
70 | while (f < n) f *= 2; t++;
| ^
# | 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... |