#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;
#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)
#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif
int n;
int ind = 1;
vi state;
vi x, y;
int k=0;
int numexits = 0;
int build_tree(int d, vi& x, vi& y)
{
int u = ind++;
if (d==0)
{
numexits += 2;
x[u] = inf;
y[u] = inf;
return u;
}
y[u] = build_tree(d - 1, x, y);
x[u] = build_tree(d - 1, x, y);
return u;
}
int* lastv = 0;
int statesum = 0;
void traverse(int u, int t)
{
//cout << u << " ";
int& v = state[u]?y[u]:x[u];
if (v == -1) return;
statesum += state[u] == 0 ? 1 : -1;
state[u] ^= 1;
if (v==inf)
{
lastv = &v;
v = -t;
return;
}
traverse(v, t);
}
void create_circuit(int m, std::vector<int> a)
{
n = sz(a);
vi c(m + 1, -1);
c[0] = a[0];
n--;
a.erase(a.begin());
while ((1<<(k+1))<=n)
{
k++;
}
state.resize(1 << (k+1));
x.resize(1 << (k+1), inf);
y.resize(1 << (k+1), inf);
build_tree(k, x, y);
/*rep(i, sz(x))
{
if (x[i]!=inf) cout << (i) << " " << x[i] << "\n";
if (y[i] != inf) cout << (i) << " " << y[i] << "\n";
}*/
rep(i, n)
{
traverse(1, a[i]);
}
repp(i, n, (1<<(k+1)))
{
traverse(1, -1);
if (statesum == 0)
{
*lastv = 0;
//cout << "ASD";
break;
}
//cout << "\n";
}
rep(i, sz(x)) x[i] *= -1, y[i] *= -1;
rep(i, sz(x))
{
if (x[i] == -inf) x[i] = -1;
if (y[i] == -inf) y[i] = -1;
}
x.erase(x.begin());
y.erase(y.begin());
/*int u = sz(x);
rep(i, sz(x))
{
cout << -(i+1) << " " << x[i] << "\n";
cout << -(i+1) << " " << y[i] << "\n";
}*/
answer(c, x, y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
53 ms |
5060 KB |
Output is correct |
3 |
Partially correct |
100 ms |
8640 KB |
Output is partially correct |
4 |
Partially correct |
111 ms |
10656 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
53 ms |
5060 KB |
Output is correct |
3 |
Partially correct |
100 ms |
8640 KB |
Output is partially correct |
4 |
Partially correct |
111 ms |
10656 KB |
Output is partially correct |
5 |
Partially correct |
110 ms |
11220 KB |
Output is partially correct |
6 |
Partially correct |
104 ms |
11324 KB |
Output is partially correct |
7 |
Partially correct |
106 ms |
11320 KB |
Output is partially correct |
8 |
Partially correct |
111 ms |
11192 KB |
Output is partially correct |
9 |
Partially correct |
103 ms |
9584 KB |
Output is partially correct |
10 |
Partially correct |
104 ms |
11068 KB |
Output is partially correct |
11 |
Partially correct |
109 ms |
10664 KB |
Output is partially correct |
12 |
Partially correct |
101 ms |
9800 KB |
Output is partially correct |
13 |
Correct |
54 ms |
6216 KB |
Output is correct |
14 |
Partially correct |
102 ms |
10312 KB |
Output is partially correct |
15 |
Partially correct |
103 ms |
10436 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
600 KB |
Output is partially correct |
17 |
Correct |
53 ms |
5996 KB |
Output is correct |
18 |
Correct |
55 ms |
5972 KB |
Output is correct |
19 |
Partially correct |
96 ms |
9796 KB |
Output is partially correct |
20 |
Partially correct |
105 ms |
11068 KB |
Output is partially correct |
21 |
Partially correct |
115 ms |
10640 KB |
Output is partially correct |
22 |
Partially correct |
107 ms |
10580 KB |
Output is partially correct |