#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
void create_circuit(int m, vector<int> a) {
int n = a.size();
int reidx[m + 1];
for (int i = 1; i <= m; i++) reidx[i] = 0;
for (int x : a) reidx[x] = 1;
int base = 0;
for (int i = 1; i <= m; i++) {
if (reidx[i]) reidx[i] = ++base;
}
vector<int> C(m + 1);
C[0] = a[0];
for (int i = 1; i <= m; i++) {
C[i] = -reidx[i];
}
vector<int> sto[base + 1];
for (int i = 1; i < n; i++) {
sto[reidx[a[i - 1]]].pb(a[i]);
}
sto[reidx[a[n - 1]]].pb(0);
// for (int i = 1; i <= m; i++) cerr << reidx[i] << ' ';
// cerr << endl;
// for (int i = 1; i <= base; i++) {
// for (int x : sto[i]) cerr << x << ' ';
// cerr << endl;
// }
vector<pii> nxt;
vector<int> access;
vector<bool> state;
auto recur = [&](auto&& self, int ptr, int dep, int rem) -> int {
if (rem <= 0) {
nxt[ptr] = {ptr, 0};
return 0;
}
// assign right
if (dep == 1) {
nxt[ptr].ss = -2;
rem--;
} else {
int nptr = nxt.size();
nxt[ptr].ss = nptr;
nxt.pb({-1, -1});
rem = self(self, nptr, dep - 1, rem);
}
// assign left
if (dep == 1) {
if (rem == 0) {
nxt[ptr].ff = 0;
} else {
nxt[ptr].ff = -2;
rem--;
}
} else {
int nptr = nxt.size();
nxt[ptr].ff = nptr;
nxt.pb({-1, -1});
rem = self(self, nptr, dep - 1, rem);
}
return rem;
};
auto gen = [&](auto&& self, int sz) -> int {
int logsz = 1;
while ((1 << logsz) < sz) logsz++;
nxt = {{-1, -1}};
recur(recur, 0, logsz, sz);
int used = nxt.size();
int dirs = used;
state.resize(used, 0);
access.clear();
int cnt = 0;
// cerr << "Gen size " << sz << ":\n";
// for (pii cur : nxt) cerr << cur.ff << ' ' << cur.ss << endl;
// cerr << "End" << endl;
do {
int st = 0;
while (true) {
if (!state[st]) {
state[st] = !state[st]; cnt++;
if (nxt[st].ff == -2) {
nxt[st].ff = dirs++;
break;
} else {
st = nxt[st].ff;
}
} else {
state[st] = !state[st]; cnt--;
if (nxt[st].ss == -2) {
nxt[st].ss = dirs++;
break;
} else {
st = nxt[st].ss;
}
}
}
} while (cnt > 0);
int intend = dirs - sz;
for (pii &cur : nxt) {
if (cur.ff >= used && cur.ff < intend) cur.ff = 0;
if (cur.ss >= used && cur.ss < intend) cur.ss = 0;
}
// cerr << "Gen size " << sz << ":\n";
// for (pii cur : nxt) cerr << cur.ff << ' ' << cur.ss << endl;
// cerr << "End" << endl;
return intend;
};
vector<int> X(base), Y(base);
int cnt = base;
for (int i = 1; i <= base; i++) {
if (sto[i].size() == 1) {
X[i - 1] = -i;
Y[i - 1] = sto[i].front();
continue;
}
int assign = gen(gen, sto[i].size());
auto decrypt = [&](int x) -> int {
if (x == 0) return -i;
else if (x < assign) return -(x + cnt);
else return sto[i][x - assign];
};
// cerr << "Gen " << i << ": \n";
// cerr << assign << endl;
// for (pii cur : nxt) cerr << cur.ff << ' ' << cur.ss << endl;
// cerr << "End of gen " << i << endl;
X[i - 1] = decrypt(nxt[0].ff); Y[i - 1] = decrypt(nxt[0].ss);
for (int j = 1; j < (int)(nxt.size()); j++) {
// cerr << "decrypt " << nxt[j].ff << ' ' << decrypt(nxt[j].ff) << endl;
X.pb(decrypt(nxt[j].ff));
Y.pb(decrypt(nxt[j].ss));
}
cnt = (int)(X.size());
}
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
30 ms |
7472 KB |
Output is correct |
3 |
Correct |
26 ms |
7004 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
1840 KB |
Output is correct |
6 |
Correct |
42 ms |
10588 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
30 ms |
7472 KB |
Output is correct |
3 |
Correct |
26 ms |
7004 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
1840 KB |
Output is correct |
6 |
Correct |
42 ms |
10588 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
7516 KB |
Output is correct |
9 |
Correct |
44 ms |
9820 KB |
Output is correct |
10 |
Correct |
59 ms |
11348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
30 ms |
7472 KB |
Output is correct |
3 |
Correct |
26 ms |
7004 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
1840 KB |
Output is correct |
6 |
Correct |
42 ms |
10588 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
7516 KB |
Output is correct |
9 |
Correct |
44 ms |
9820 KB |
Output is correct |
10 |
Correct |
59 ms |
11348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
68 ms |
11208 KB |
Output is correct |
15 |
Correct |
37 ms |
6060 KB |
Output is correct |
16 |
Correct |
70 ms |
8892 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
63 ms |
11288 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Output is partially correct |
2 |
Correct |
52 ms |
7160 KB |
Output is correct |
3 |
Partially correct |
49 ms |
7156 KB |
Output is partially correct |
4 |
Correct |
75 ms |
11072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Output is partially correct |
2 |
Correct |
52 ms |
7160 KB |
Output is correct |
3 |
Partially correct |
49 ms |
7156 KB |
Output is partially correct |
4 |
Correct |
75 ms |
11072 KB |
Output is correct |
5 |
Partially correct |
78 ms |
13748 KB |
Output is partially correct |
6 |
Partially correct |
84 ms |
13060 KB |
Output is partially correct |
7 |
Partially correct |
83 ms |
13300 KB |
Output is partially correct |
8 |
Partially correct |
71 ms |
12280 KB |
Output is partially correct |
9 |
Partially correct |
46 ms |
6324 KB |
Output is partially correct |
10 |
Partially correct |
72 ms |
11360 KB |
Output is partially correct |
11 |
Partially correct |
60 ms |
10292 KB |
Output is partially correct |
12 |
Partially correct |
39 ms |
6816 KB |
Output is partially correct |
13 |
Partially correct |
50 ms |
8880 KB |
Output is partially correct |
14 |
Partially correct |
50 ms |
8820 KB |
Output is partially correct |
15 |
Partially correct |
51 ms |
9012 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
604 KB |
Output is partially correct |
17 |
Partially correct |
36 ms |
6568 KB |
Output is partially correct |
18 |
Partially correct |
38 ms |
6540 KB |
Output is partially correct |
19 |
Partially correct |
42 ms |
6772 KB |
Output is partially correct |
20 |
Partially correct |
56 ms |
9960 KB |
Output is partially correct |
21 |
Partially correct |
64 ms |
10136 KB |
Output is partially correct |
22 |
Partially correct |
53 ms |
9508 KB |
Output is partially correct |