using namespace std;
#include<vector>
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
int find_s(int M, vector<int> A){
int N = A.size();
A.push_back(0);
std::vector<int> C(M + 1,19);
std::vector<int> X(2*N+1), Y(2*N+1);
int l = 0, r = N;
int wr = 0;
while(l<r){
int rt = l-1;
int lt = rt - (r-l)/2;
int it = r;
for(int i = lt; i<=rt; i++){
if(r == N){
Y[wr]=it;
it--;
if(it >=l){
X[wr]=it;
}else{
X[wr] = 2;
}
it--;wr++;
}
else{
Y[wr]=it;
it--;
if(it >=l){
X[wr]=it;
}else{
X[wr] = 2;
}
it--,wr++;
}
}
l=lt,r=rt;
}
return l;
}
#include <algorithm>
#define vi vector<int>
vi getper(int N){
if(N==1)return {0};
vi per1= getper(N/2), per2 = getper((N+1)/2);
vi ans;
for(int i = 0; i < N; i++){
if(i%2){
ans.push_back(per1[i/2]+(N+1)/2);
}else{
ans.push_back(per2[i/2]);
}
}
return ans;
}
void create_circuit(int M, std::vector<int> A) {
int s = find_s(M,A);
int N = A.size();
vector<int> per;
A.push_back(0);
std::vector<int> C(M + 1,s);
std::vector<int> X(-s), Y(-s);
int l = 0, r = N;
int wr = 0;
while(l<r){
int rt = l-1;
int lt = rt - (r-l)/2;
int it = r;
for(int i = lt; i<=rt; i++){
if(r == N){
Y[wr]=it;
it--;
if(it != r-1 || (r-l)%2){
X[wr]=it;
it--;
}else{
X[wr] = s;
}
wr++;
}
else{
Y[wr]=it;
it--;
if(it != r-1 || (r-l)%2){
X[wr]=it;
it--;
}else{
X[wr] = s;
}
wr++;
}
}
l=lt,r=rt;
}
int st = s;
while(st!=N){
if(st < 0){
int stag = X[-1-st];
swap(X[-1-st],Y[-1-st]);
st = stag;
}else{
per.push_back(st);
st = s;
}
}
per.push_back(N);
vi q(N+1);
for(int i = 0; i <= N; i++)q[per[i]]=i;
for(int i = 0; i< (-s); i++){
if(X[i]>=0)X[i] = A[q[X[i]]];
if(Y[i]>=0)Y[i] = A[q[Y[i]]];
}
per.push_back(0);
answer(C,X,Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
20 ms |
6220 KB |
Output is correct |
3 |
Correct |
19 ms |
5704 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1888 KB |
Output is correct |
6 |
Correct |
30 ms |
8172 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
20 ms |
6220 KB |
Output is correct |
3 |
Correct |
19 ms |
5704 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1888 KB |
Output is correct |
6 |
Correct |
30 ms |
8172 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
9536 KB |
Output is correct |
9 |
Correct |
38 ms |
10300 KB |
Output is correct |
10 |
Correct |
56 ms |
14600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
2 |
Correct |
20 ms |
6220 KB |
Output is correct |
3 |
Correct |
19 ms |
5704 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1888 KB |
Output is correct |
6 |
Correct |
30 ms |
8172 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
36 ms |
9536 KB |
Output is correct |
9 |
Correct |
38 ms |
10300 KB |
Output is correct |
10 |
Correct |
56 ms |
14600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
55 ms |
13696 KB |
Output is correct |
15 |
Correct |
35 ms |
9000 KB |
Output is correct |
16 |
Correct |
54 ms |
13280 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 |
55 ms |
14140 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
424 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
8124 KB |
Output is correct |
3 |
Correct |
31 ms |
8000 KB |
Output is correct |
4 |
Correct |
49 ms |
11744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
8124 KB |
Output is correct |
3 |
Correct |
31 ms |
8000 KB |
Output is correct |
4 |
Correct |
49 ms |
11744 KB |
Output is correct |
5 |
Correct |
54 ms |
13020 KB |
Output is correct |
6 |
Correct |
69 ms |
12800 KB |
Output is correct |
7 |
Correct |
55 ms |
12792 KB |
Output is correct |
8 |
Correct |
52 ms |
12512 KB |
Output is correct |
9 |
Correct |
32 ms |
8008 KB |
Output is correct |
10 |
Correct |
59 ms |
12508 KB |
Output is correct |
11 |
Correct |
59 ms |
12016 KB |
Output is correct |
12 |
Correct |
32 ms |
8256 KB |
Output is correct |
13 |
Correct |
34 ms |
8752 KB |
Output is correct |
14 |
Correct |
34 ms |
8756 KB |
Output is correct |
15 |
Correct |
35 ms |
8776 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
30 ms |
8464 KB |
Output is correct |
18 |
Correct |
32 ms |
8328 KB |
Output is correct |
19 |
Correct |
32 ms |
8264 KB |
Output is correct |
20 |
Correct |
51 ms |
12408 KB |
Output is correct |
21 |
Correct |
60 ms |
11960 KB |
Output is correct |
22 |
Correct |
50 ms |
12080 KB |
Output is correct |