#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
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 |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4476 KB |
Output is correct |
3 |
Correct |
30 ms |
4476 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
47 ms |
6168 KB |
Output is correct |
7 |
Runtime error |
148 ms |
262144 KB |
Execution killed with signal 9 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4476 KB |
Output is correct |
3 |
Correct |
30 ms |
4476 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
47 ms |
6168 KB |
Output is correct |
7 |
Runtime error |
148 ms |
262144 KB |
Execution killed with signal 9 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4476 KB |
Output is correct |
3 |
Correct |
30 ms |
4476 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
47 ms |
6168 KB |
Output is correct |
7 |
Runtime error |
148 ms |
262144 KB |
Execution killed with signal 9 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
51 ms |
6672 KB |
Output is correct |
3 |
Correct |
54 ms |
6524 KB |
Output is correct |
4 |
Correct |
86 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
51 ms |
6672 KB |
Output is correct |
3 |
Correct |
54 ms |
6524 KB |
Output is correct |
4 |
Correct |
86 ms |
9676 KB |
Output is correct |
5 |
Correct |
90 ms |
10084 KB |
Output is correct |
6 |
Correct |
89 ms |
9832 KB |
Output is correct |
7 |
Correct |
90 ms |
9836 KB |
Output is correct |
8 |
Correct |
87 ms |
9676 KB |
Output is correct |
9 |
Correct |
55 ms |
6488 KB |
Output is correct |
10 |
Correct |
92 ms |
9700 KB |
Output is correct |
11 |
Correct |
87 ms |
9704 KB |
Output is correct |
12 |
Correct |
52 ms |
6764 KB |
Output is correct |
13 |
Correct |
55 ms |
6776 KB |
Output is correct |
14 |
Correct |
56 ms |
7216 KB |
Output is correct |
15 |
Correct |
56 ms |
7404 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
55 ms |
6684 KB |
Output is correct |
18 |
Correct |
52 ms |
6720 KB |
Output is correct |
19 |
Correct |
54 ms |
6724 KB |
Output is correct |
20 |
Correct |
87 ms |
9672 KB |
Output is correct |
21 |
Correct |
85 ms |
9680 KB |
Output is correct |
22 |
Correct |
83 ms |
9676 KB |
Output is correct |