#include<bits/stdc++.h>
#include "doll.h"
using namespace std;
vector<int> A, C, X, Y;
int S = 0;
int create_switch() {
X.push_back(-1);
Y.push_back(-1);
S++;
return -S;
}
void build(int trigger, vector<int> in) {
if((int)in.empty()) {
C[trigger] = 0;
return;
}
if((int)in.size() == 1) {
C[trigger] = A[in[0] + 1];
return;
}
int k = 1;
vector<int> order = {0};
while(k < (int)in.size()) {
if(k == 1) C[trigger] = create_switch();
else {
int len = S;
for(int i = len - k / 2; i < len; i++) {
X[i] = create_switch();
Y[i] = create_switch();
}
}
vector<int> new_ord;
for(int i = 0; i < k; i++)
new_ord.push_back(order[i]),
new_ord.push_back(order[i] + k);
order = new_ord;
k *= 2;
}
for(int i = S - k / 2; i < S; i++) {
int y = i - S + k / 2;
X[i] = (order[y * 2] < k - (int)in.size() ? C[trigger] : A[in[ order[2 * y] - k + (int)in.size() ] + 1]);
Y[i] = (order[y * 2 + 1] < k - (int)in.size() ? C[trigger] : A[in[ order[2 * y + 1] - k + (int)in.size() ] + 1]);
}
}
void build1() {
int k = 1;
vector<int> order = {0};
while(k < (int)A.size()) {
if(k == 1) C[0] = create_switch();
else {
int len = S;
for(int i = len - k / 2; i < len; i++) {
X[i] = create_switch();
Y[i] = create_switch();
}
}
vector<int> new_ord;
for(int i = 0; i < k; i++)
new_ord.push_back(order[i]),
new_ord.push_back(order[i] + k);
order = new_ord;
k *= 2;
}
for(int i = S - k / 2; i < S; i++) {
int y = i - S + k / 2;
X[i] = (order[y * 2] < k - (int)A.size() ? C[0] : A[order[2 * y] - k + (int)A.size() ]);
Y[i] = (order[y * 2 + 1] < k - (int)A.size() ? C[0] : A[order[2 * y + 1] - k + (int)A.size() ]);
}
}
const int N = 1e5 + 10;
vector<int> g[N];
void create_circuit(int M, std::vector<int> a) {
C.resize(M + 1);
a.push_back(0);
A = a;
int N = (int)A.size();
if((N & N - 1) > 0) {
for(int i = 0; i < N; i++) {
g[A[i]].push_back(i);
}
C[0] = A[0];
for(int i = 1; i <= M; i++) {
build(i, g[i]);
}
answer(C, X, Y);
} else {
build1();
for(int i = 1; i <= M; i++) C[i] = C[0];
answer(C, X, Y);
}
}
// int main() {
// create_circuit(0, vector<int>());
// }
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:84:15: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
84 | if((N & N - 1) > 0) {
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
23 ms |
6608 KB |
Output is correct |
3 |
Correct |
18 ms |
6364 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
26 ms |
8276 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
23 ms |
6608 KB |
Output is correct |
3 |
Correct |
18 ms |
6364 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
26 ms |
8276 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
39 ms |
9232 KB |
Output is correct |
9 |
Correct |
40 ms |
9688 KB |
Output is correct |
10 |
Correct |
64 ms |
13104 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
23 ms |
6608 KB |
Output is correct |
3 |
Correct |
18 ms |
6364 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
26 ms |
8276 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
39 ms |
9232 KB |
Output is correct |
9 |
Correct |
40 ms |
9688 KB |
Output is correct |
10 |
Correct |
64 ms |
13104 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
86 ms |
14884 KB |
Output is correct |
15 |
Correct |
48 ms |
9036 KB |
Output is correct |
16 |
Correct |
82 ms |
12088 KB |
Output is correct |
17 |
Correct |
1 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
69 ms |
13608 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
30 ms |
9044 KB |
Output is correct |
3 |
Partially correct |
50 ms |
13436 KB |
Output is partially correct |
4 |
Partially correct |
56 ms |
14484 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
30 ms |
9044 KB |
Output is correct |
3 |
Partially correct |
50 ms |
13436 KB |
Output is partially correct |
4 |
Partially correct |
56 ms |
14484 KB |
Output is partially correct |
5 |
Partially correct |
94 ms |
16644 KB |
Output is partially correct |
6 |
Partially correct |
90 ms |
17928 KB |
Output is partially correct |
7 |
Partially correct |
88 ms |
17484 KB |
Output is partially correct |
8 |
Partially correct |
85 ms |
18480 KB |
Output is partially correct |
9 |
Partially correct |
49 ms |
12088 KB |
Output is partially correct |
10 |
Partially correct |
80 ms |
18808 KB |
Output is partially correct |
11 |
Partially correct |
79 ms |
19336 KB |
Output is partially correct |
12 |
Partially correct |
51 ms |
13008 KB |
Output is partially correct |
13 |
Partially correct |
57 ms |
11708 KB |
Output is partially correct |
14 |
Partially correct |
58 ms |
11372 KB |
Output is partially correct |
15 |
Partially correct |
57 ms |
10916 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
2900 KB |
Output is partially correct |
17 |
Correct |
30 ms |
8636 KB |
Output is correct |
18 |
Partially correct |
42 ms |
11272 KB |
Output is partially correct |
19 |
Partially correct |
45 ms |
11652 KB |
Output is partially correct |
20 |
Partially correct |
63 ms |
14564 KB |
Output is partially correct |
21 |
Partially correct |
84 ms |
17224 KB |
Output is partially correct |
22 |
Partially correct |
56 ms |
13768 KB |
Output is partially correct |