#include "doll.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int inf = 1e7;
void subtask_1_2_3(int m, vector<int> A){
int n = A.size();
A.pb(inf);
vector<vector<int>> pos(m);
for(int i = 0; i < n; i++) pos[A[i]-1].pb(i);
vector<int> C(m+1, 0), X, Y;
C[0] = A[0];
int ls = 0;
for(int i = 0; i < m; i++) if(!pos[i].empty()){
if(pos[i].size() == 1){
C[i+1] = A[pos[i][0]+1];
}
else if(pos[i].size() == 2){
X.pb(A[pos[i][0]+1]), Y.pb(A[pos[i][1]+1]);
C[i+1] = -int(X.size());
}
else if(pos[i].size() == 4){
C[i+1] = -int(X.size()+1);
X.pb(-int(X.size()+2)), Y.pb(-int(Y.size()+3));
X.pb(A[pos[i][0]+1]), X.pb(A[pos[i][1]+1]);
Y.pb(A[pos[i][2]+1]), Y.pb(A[pos[i][3]+1]);
}
else{
C[i+1] = -int(X.size()+1);
X.pb(-int(X.size()+2)), Y.pb(-int(Y.size()+3));
X.pb(A[pos[i][0]+1]), X.pb(A[pos[i][1]+1]);
Y.pb(A[pos[i][2]+1]), Y.pb(ls);
ls = -int(X.size())+2;
}
}
for(int &x: C) if(x == inf) x = ls;
for(int &x: X) if(x == inf) x = ls;
for(int &x: Y) if(x == inf) x = ls;
answer(C, X, Y);
}
void create_circuit(int m, vector<int> A){
int n = A.size();
vector<int> cnt(m, 0);
for(int &x: A) cnt[x-1]++;
if(*max_element(cnt.begin(), cnt.end()) <= 4){
subtask_1_2_3(m, A);
return;
}
int k = 1;
while(k < n) k*=2;
vector<int> sth(2*k, -2);
vector<pair<int, int>> candidates;
for(int i = k; i < 2*k; i++){
int j = i, pos = 0;
while(j != 1){
if(j&1) pos++;
pos<<=1;
j>>=1;
}
pos>>=1;
if(2*k-i-1 < n) candidates.pb({pos, i});
sth[i] = -1;
}
sort(candidates.begin(), candidates.end());
for(int i = 1; i < n; i++) sth[candidates[i-1].sc] = A[i];
sth[candidates.back().sc] = 0;
vector<int> C(m+1, -1), X, Y;
C[0] = A[0];
for(int i = k-1; i >= 1; i--){
if(sth[2*i] == -1 && sth[2*i+1] == -1) sth[i] = -1;
}
function<int(int)> rec = [&](int i){
X.pb(0), Y.pb(0);
int j = X.size();
if(sth[2*i] == -1) X[j-1] = -1;
else if(sth[2*i] >= 0) X[j-1] = sth[2*i];
else X[j-1] = rec(2*i);
if(sth[2*i+1] == -1) Y[j-1] = -1;
else if(sth[2*i+1] >= 0) Y[j-1] = sth[2*i+1];
else Y[j-1] = rec(2*i+1);
return -j;
};
rec(1);
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
20 ms |
6992 KB |
Output is correct |
3 |
Correct |
16 ms |
5684 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
4180 KB |
Output is correct |
6 |
Correct |
24 ms |
8524 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
20 ms |
6992 KB |
Output is correct |
3 |
Correct |
16 ms |
5684 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
4180 KB |
Output is correct |
6 |
Correct |
24 ms |
8524 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
34 ms |
8912 KB |
Output is correct |
9 |
Correct |
37 ms |
10448 KB |
Output is correct |
10 |
Correct |
53 ms |
13856 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
20 ms |
6992 KB |
Output is correct |
3 |
Correct |
16 ms |
5684 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
4180 KB |
Output is correct |
6 |
Correct |
24 ms |
8524 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
34 ms |
8912 KB |
Output is correct |
9 |
Correct |
37 ms |
10448 KB |
Output is correct |
10 |
Correct |
53 ms |
13856 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
64 ms |
13468 KB |
Output is correct |
15 |
Correct |
39 ms |
7688 KB |
Output is correct |
16 |
Correct |
54 ms |
11076 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
63 ms |
13196 KB |
Output is correct |
21 |
Correct |
0 ms |
304 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
38 ms |
6728 KB |
Output is correct |
3 |
Correct |
45 ms |
7752 KB |
Output is correct |
4 |
Correct |
63 ms |
10672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
38 ms |
6728 KB |
Output is correct |
3 |
Correct |
45 ms |
7752 KB |
Output is correct |
4 |
Correct |
63 ms |
10672 KB |
Output is correct |
5 |
Correct |
68 ms |
11072 KB |
Output is correct |
6 |
Correct |
83 ms |
10832 KB |
Output is correct |
7 |
Correct |
70 ms |
10940 KB |
Output is correct |
8 |
Correct |
69 ms |
10780 KB |
Output is correct |
9 |
Correct |
43 ms |
7748 KB |
Output is correct |
10 |
Correct |
81 ms |
10724 KB |
Output is correct |
11 |
Correct |
74 ms |
10752 KB |
Output is correct |
12 |
Correct |
56 ms |
7772 KB |
Output is correct |
13 |
Correct |
40 ms |
6916 KB |
Output is correct |
14 |
Correct |
43 ms |
7964 KB |
Output is correct |
15 |
Correct |
56 ms |
7980 KB |
Output is correct |
16 |
Correct |
2 ms |
568 KB |
Output is correct |
17 |
Correct |
46 ms |
6728 KB |
Output is correct |
18 |
Correct |
45 ms |
6732 KB |
Output is correct |
19 |
Correct |
42 ms |
7740 KB |
Output is correct |
20 |
Correct |
72 ms |
10688 KB |
Output is correct |
21 |
Correct |
74 ms |
10688 KB |
Output is correct |
22 |
Correct |
69 ms |
10664 KB |
Output is correct |