#include "doll.h"
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
vector<vector<int> > qs(M + 1);
for(int i = 0; i < N; ++i) {
qs[A[i]].push_back(i);
}
bool subtask3 = true;
for(int i = 1; i <= M; ++i) {
if(qs[i].size() >= 5) {
subtask3 = false;
}
}
if(subtask3) {
vector<int> C1(M + 1, 0), X1, Y1;
A.push_back(0);
C1[0] = A[0];
for(int i = 1; i <= M; ++i) {
if(qs[i].size() == 0) continue;
int ns = X1.size();
if(qs[i].size() == 1) {
C1[i] = A[qs[i][0] + 1];
}
if(qs[i].size() == 2) {
C1[i] = -(ns + 1);
X1.push_back(A[qs[i][0] + 1]);
Y1.push_back(A[qs[i][1] + 1]);
}
if(qs[i].size() == 3) {
C1[i] = -(ns + 1);
X1.push_back(-(ns + 2));
Y1.push_back(-(ns + 3));
X1.push_back(-(ns + 1));
Y1.push_back(A[qs[i][1] + 1]);
X1.push_back(A[qs[i][0] + 1]);
Y1.push_back(A[qs[i][2] + 1]);
}
if(qs[i].size() == 4) {
C1[i] = -(ns + 1);
X1.push_back(-(ns + 2));
Y1.push_back(-(ns + 3));
X1.push_back(A[qs[i][0] + 1]);
Y1.push_back(A[qs[i][2] + 1]);
X1.push_back(A[qs[i][1] + 1]);
Y1.push_back(A[qs[i][3] + 1]);
}
}
answer(C1, X1, Y1);
return;
}
int bits = 1;
while((1 << bits) < N) ++bits;
vector<int> C(M + 1, -1);
C[0] = A[0];
vector<int> X((1 << bits) - 1, -1), Y((1 << bits) - 1, -1);
for(int i = 1; i < 1 << (bits - 1); ++i) {
X[i - 1] = -(2 * i);
Y[i - 1] = -(2 * i + 1);
}
vector<int> perm;
for(int i = 1 << bits; i < 2 << bits; ++i) {
perm.push_back(i);
}
sort(perm.begin(), perm.end(), [&](int i, int j) {
for(int k = 0; k < bits; ++k) {
if(((i >> k) & 1) != ((j >> k) & 1)) {
return ((i >> k) & 1) < ((j >> k) & 1);
}
}
return false;
});
for(int i = 0; i < 1 << bits; ++i) {
int tar = i - ((1 << bits) - N);
if(tar < 0) tar = -1;
else if(i != ((1 << bits) - 1)) tar = A[tar + 1];
else tar = 0;
if(perm[i] % 2 == 0) {
X[perm[i] / 2 - 1] = tar;
}
else {
Y[perm[i] / 2 - 1] = tar;
}
}
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
36 ms |
6344 KB |
Output is correct |
3 |
Correct |
27 ms |
5160 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
3804 KB |
Output is correct |
6 |
Correct |
50 ms |
7620 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
36 ms |
6344 KB |
Output is correct |
3 |
Correct |
27 ms |
5160 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
3804 KB |
Output is correct |
6 |
Correct |
50 ms |
7620 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
59 ms |
7208 KB |
Output is correct |
9 |
Correct |
60 ms |
8512 KB |
Output is correct |
10 |
Correct |
90 ms |
11296 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 |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
36 ms |
6344 KB |
Output is correct |
3 |
Correct |
27 ms |
5160 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
3804 KB |
Output is correct |
6 |
Correct |
50 ms |
7620 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
59 ms |
7208 KB |
Output is correct |
9 |
Correct |
60 ms |
8512 KB |
Output is correct |
10 |
Correct |
90 ms |
11296 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 |
10920 KB |
Output is correct |
15 |
Correct |
54 ms |
5960 KB |
Output is correct |
16 |
Correct |
85 ms |
8628 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
224 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
114 ms |
10660 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Output is partially correct |
2 |
Correct |
97 ms |
5556 KB |
Output is correct |
3 |
Partially correct |
190 ms |
9152 KB |
Output is partially correct |
4 |
Partially correct |
199 ms |
9900 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Output is partially correct |
2 |
Correct |
97 ms |
5556 KB |
Output is correct |
3 |
Partially correct |
190 ms |
9152 KB |
Output is partially correct |
4 |
Partially correct |
199 ms |
9900 KB |
Output is partially correct |
5 |
Partially correct |
216 ms |
12636 KB |
Output is partially correct |
6 |
Partially correct |
213 ms |
11820 KB |
Output is partially correct |
7 |
Partially correct |
219 ms |
12012 KB |
Output is partially correct |
8 |
Partially correct |
213 ms |
11400 KB |
Output is partially correct |
9 |
Partially correct |
184 ms |
9152 KB |
Output is partially correct |
10 |
Partially correct |
202 ms |
10652 KB |
Output is partially correct |
11 |
Partially correct |
213 ms |
11000 KB |
Output is partially correct |
12 |
Partially correct |
217 ms |
9852 KB |
Output is partially correct |
13 |
Correct |
142 ms |
6844 KB |
Output is correct |
14 |
Partially correct |
195 ms |
10552 KB |
Output is partially correct |
15 |
Partially correct |
204 ms |
10912 KB |
Output is partially correct |
16 |
Partially correct |
5 ms |
588 KB |
Output is partially correct |
17 |
Correct |
99 ms |
5920 KB |
Output is correct |
18 |
Correct |
106 ms |
6020 KB |
Output is correct |
19 |
Partially correct |
190 ms |
9632 KB |
Output is partially correct |
20 |
Partially correct |
200 ms |
10560 KB |
Output is partially correct |
21 |
Partially correct |
197 ms |
10732 KB |
Output is partially correct |
22 |
Partially correct |
217 ms |
10340 KB |
Output is partially correct |