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;
typedef vector<int> vi;
namespace solution {
vi c, x, y;
int s;
vector<bool> q;
int swicch(int l, int r) {
int p = l + r >> 1;
int i = s++;
x.push_back(0);
y.push_back(0);
q.push_back(false);
if(l + r == 2) {
if(l) x[i] = -1;
return -(i + 1);
}
if(l >= p) {
x[i] = -1;
y[i] = swicch(l - p, r);
return -(i + 1);
}
x[i] = swicch(l, r - p);
y[i] = swicch(0, p);
return -(i + 1);
}
void push(int i, int v) {
int &j = (q[i] ? y[i] : x[i]);
q[i] = !q[i];
if(!j) {j = v; return;}
push(-(j + 1), v);
}
}
void create_circuit (int m, vi a) {
using namespace solution;
int n = a.size();
s = 0;
x.clear(); x.reserve(n * 4);
y.clear(); y.reserve(n * 4);
q.clear(); q.reserve(n * 4);
if(n == 1) {
c.assign(m + 1, 0);
c[0] = a[0];
answer(c, x, y);
return;
}
c.assign(m + 1, -1);
c[0] = a[0];
int e = 0;
for(; __builtin_popcount(e + n) > 1; ++e);
swicch(e, n);
for(int i = 1; i < n; ++i) push(0, a[i]);
answer(c, x, y);
}
Compilation message (stderr)
doll.cpp: In function 'int solution::swicch(int, int)':
doll.cpp:13:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int p = l + r >> 1;
| ~~^~~
# | 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... |