#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int i, n, m, s, g, j, kk;
vector<int> C;
vector<int> X;
vector<int> Y;
vector<int> adj[100005];
bool visited[100005];
bool finished[200005];
vector<vector<int> > groups;
vector<int> tmp;
bool vis;
vector<int> sw;
vector<int> st;
vector<pair<int, int> > pos;
void new_switch() {
sw.push_back(--s);
st.push_back(0);
X.push_back(sw.front());
Y.push_back(sw.front());
}
void dfs(int x) {
if (st[-x-1] == 0) {
st[-x-1] ^= 1;
if (X[-x-1] == sw.front()) pos.push_back(make_pair(-x-1, 0));
else dfs(X[-x-1]);
}
else {
st[-x-1] ^= 1;
if (Y[-x-1] == sw.front()) pos.push_back(make_pair(-x-1, 1));
else dfs(Y[-x-1]);
}
}
void create_switch(int i) {
int num = (int)adj[i].size();
if (num == 0) C[i] = i;
else if (num == 1) C[i] = adj[i][0];
else {
sw.clear();
kk = 1;
while (kk < num) kk *= 2;
--kk;
new_switch();
C[i] = s;
for (int j=1; j < kk; ++j) {
new_switch();
if (j&1) X[-sw[j>>1]-1] = s;
else Y[-sw[(j-1)>>1]-1] = s;
}
pos.clear();
for (int j=0; j <= kk; ++j) dfs(sw.front());
for (j=num-1; j >= 0; --j) {
if (pos[kk].second == 0) X[pos[kk].first] = adj[i][j];
else Y[pos[kk].first] = adj[i][j];
--kk;
}
}
}
void create_circuit(int M, vector<int> A) {
m = M;
n = (int)A.size();
fill(finished, finished+n+1, false);
C.resize(M+1);
X.clear();
Y.clear();
st.clear();
s = 0;
A.push_back(0);
for (i=0; i < n; ++i) adj[A[i]].push_back(A[i+1]);
C[0] = A[0];
for (i=1; i <= M; ++i) create_switch(i);
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2664 KB |
Output is correct |
2 |
Correct |
21 ms |
6920 KB |
Output is correct |
3 |
Correct |
17 ms |
6636 KB |
Output is correct |
4 |
Correct |
2 ms |
2660 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
24 ms |
8544 KB |
Output is correct |
7 |
Correct |
1 ms |
2664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2664 KB |
Output is correct |
2 |
Correct |
21 ms |
6920 KB |
Output is correct |
3 |
Correct |
17 ms |
6636 KB |
Output is correct |
4 |
Correct |
2 ms |
2660 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
24 ms |
8544 KB |
Output is correct |
7 |
Correct |
1 ms |
2664 KB |
Output is correct |
8 |
Correct |
42 ms |
9840 KB |
Output is correct |
9 |
Correct |
44 ms |
10224 KB |
Output is correct |
10 |
Correct |
61 ms |
13272 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2664 KB |
Output is correct |
2 |
Correct |
21 ms |
6920 KB |
Output is correct |
3 |
Correct |
17 ms |
6636 KB |
Output is correct |
4 |
Correct |
2 ms |
2660 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
24 ms |
8544 KB |
Output is correct |
7 |
Correct |
1 ms |
2664 KB |
Output is correct |
8 |
Correct |
42 ms |
9840 KB |
Output is correct |
9 |
Correct |
44 ms |
10224 KB |
Output is correct |
10 |
Correct |
61 ms |
13272 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
69 ms |
16076 KB |
Output is correct |
15 |
Correct |
42 ms |
9496 KB |
Output is correct |
16 |
Correct |
57 ms |
13040 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
68 ms |
14680 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
46 ms |
11532 KB |
Output is correct |
3 |
Partially correct |
86 ms |
18272 KB |
Output is partially correct |
4 |
Partially correct |
98 ms |
18800 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
46 ms |
11532 KB |
Output is correct |
3 |
Partially correct |
86 ms |
18272 KB |
Output is partially correct |
4 |
Partially correct |
98 ms |
18800 KB |
Output is partially correct |
5 |
Partially correct |
79 ms |
16600 KB |
Output is partially correct |
6 |
Partially correct |
89 ms |
17876 KB |
Output is partially correct |
7 |
Partially correct |
83 ms |
17424 KB |
Output is partially correct |
8 |
Partially correct |
85 ms |
18552 KB |
Output is partially correct |
9 |
Partially correct |
85 ms |
15676 KB |
Output is partially correct |
10 |
Partially correct |
145 ms |
21788 KB |
Output is partially correct |
11 |
Partially correct |
106 ms |
19272 KB |
Output is partially correct |
12 |
Partially correct |
67 ms |
13700 KB |
Output is partially correct |
13 |
Partially correct |
55 ms |
12592 KB |
Output is partially correct |
14 |
Partially correct |
54 ms |
12344 KB |
Output is partially correct |
15 |
Partially correct |
51 ms |
11744 KB |
Output is partially correct |
16 |
Partially correct |
4 ms |
2900 KB |
Output is partially correct |
17 |
Partially correct |
51 ms |
11324 KB |
Output is partially correct |
18 |
Partially correct |
56 ms |
11372 KB |
Output is partially correct |
19 |
Partially correct |
51 ms |
11936 KB |
Output is partially correct |
20 |
Partially correct |
67 ms |
14392 KB |
Output is partially correct |
21 |
Partially correct |
101 ms |
16952 KB |
Output is partially correct |
22 |
Partially correct |
62 ms |
14472 KB |
Output is partially correct |