#include "doll.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
int N, M, l;
vim A;
int dep[(1<<20)], chk[(1<<20)], val[(1<<20)], cnt[(1<<20)], num[(1<<20)];
vim C, X, Y;
void dfs(int v) {
for (int i=1; ; ) {
if (chk[i]) {i=1; continue;}
if ((1<<(l-1))<=i) {val[i]=v; return ;}
if (cnt[i]==0) {
cnt[i]=1-cnt[i];
i=i*2;
continue;
}
if (cnt[i]==1) {
cnt[i]=1-cnt[i];
i=i*2+1;
continue;
}
}
}
void create_circuit(int M_, vim A_) {
A=A_; N=A.size(); M=M_;
A.push_back(0); N++;
for (l=0; (1<<l)<N; l++) {}
l++;
for (int i=(1<<(l-1)); i<(1<<l)-N; i++) chk[i]=1;
for (int i=(1<<(l-1))-1; i; i--) {if (chk[i*2]&&chk[i*2+1]) chk[i]=1;}
for (int i:A) dfs(i);
for (int i=1; i<(1<<(l-1)); i++) if (cnt[i]) assert(false);
int cnt=-1;
for (int i=1; i<(1<<(l-1)); i++) {
if (chk[i]) continue;
num[i]=cnt--;
}
for (int i=0; i<=M; i++) C.push_back(-1);
for (int i=1; i<(1<<(l-1)); i++) {
if (chk[i]) continue;
if (-num[i]!=X.size()+1) assert(false);
if (chk[i*2]) X.push_back(-1);
else if (i*2>=(1<<(l-1))) X.push_back(val[i*2]);
else X.push_back(num[i*2]);
if (chk[i*2+1]) assert(false);
else if (i*2+1>=(1<<(l-1))) Y.push_back(val[i*2+1]);
else Y.push_back(num[i*2+1]);
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, vim)':
doll.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if (-num[i]!=X.size()+1) assert(false);
| ~~~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
44 ms |
5816 KB |
Output is correct |
3 |
Correct |
42 ms |
5760 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
1604 KB |
Output is correct |
6 |
Correct |
64 ms |
7812 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
44 ms |
5816 KB |
Output is correct |
3 |
Correct |
42 ms |
5760 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
1604 KB |
Output is correct |
6 |
Correct |
64 ms |
7812 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
86 ms |
10016 KB |
Output is correct |
9 |
Correct |
77 ms |
10424 KB |
Output is correct |
10 |
Correct |
130 ms |
13724 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
44 ms |
5816 KB |
Output is correct |
3 |
Correct |
42 ms |
5760 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
1604 KB |
Output is correct |
6 |
Correct |
64 ms |
7812 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
86 ms |
10016 KB |
Output is correct |
9 |
Correct |
77 ms |
10424 KB |
Output is correct |
10 |
Correct |
130 ms |
13724 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
102 ms |
13352 KB |
Output is correct |
15 |
Correct |
68 ms |
9788 KB |
Output is correct |
16 |
Correct |
104 ms |
13156 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
115 ms |
13568 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
62 ms |
8236 KB |
Output is correct |
3 |
Correct |
61 ms |
8268 KB |
Output is correct |
4 |
Correct |
99 ms |
11300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
62 ms |
8236 KB |
Output is correct |
3 |
Correct |
61 ms |
8268 KB |
Output is correct |
4 |
Correct |
99 ms |
11300 KB |
Output is correct |
5 |
Correct |
98 ms |
12976 KB |
Output is correct |
6 |
Correct |
115 ms |
12456 KB |
Output is correct |
7 |
Correct |
96 ms |
12576 KB |
Output is correct |
8 |
Correct |
94 ms |
12448 KB |
Output is correct |
9 |
Correct |
63 ms |
8264 KB |
Output is correct |
10 |
Correct |
95 ms |
12064 KB |
Output is correct |
11 |
Correct |
98 ms |
11744 KB |
Output is correct |
12 |
Correct |
71 ms |
8452 KB |
Output is correct |
13 |
Correct |
64 ms |
9380 KB |
Output is correct |
14 |
Correct |
66 ms |
9060 KB |
Output is correct |
15 |
Correct |
70 ms |
9084 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
76 ms |
7716 KB |
Output is correct |
18 |
Correct |
73 ms |
8440 KB |
Output is correct |
19 |
Correct |
65 ms |
8528 KB |
Output is correct |
20 |
Correct |
91 ms |
12172 KB |
Output is correct |
21 |
Correct |
96 ms |
11684 KB |
Output is correct |
22 |
Correct |
98 ms |
11808 KB |
Output is correct |