#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
int S;
vector<int> X, Y;
vector<int> newv, pos, where;
int make_switch(int st, int dr, int idd = -1)
{
bool ok = true;
for(int i = st + 1; i <= dr; i++)
if(newv[i] != newv[st])
{
ok = false;
break;
}
if(ok) return newv[st];
if(st + 1 == dr)
{
if(idd == -1)
{
S++;
X.push_back(newv[st]);
Y.push_back(newv[dr]);
return -S;
}
else
{
X[idd - 1] = newv[st];
Y[idd - 1] = newv[dr];
return -idd;
}
}
int id = -1;
if(idd == -1)
{
S++;
id = S;
X.push_back(0);
Y.push_back(0);
}
else
id = idd;
int mij = st + (dr - st) / 2;
int sl = make_switch(st, mij);
int sr = make_switch(mij + 1, dr);
X[id - 1] = sl;
Y[id - 1] = sr;
return -id;
}
int make_switch(vector<int> v)
{
if(v.empty()) return 0;
if(v.size() == 1)
return v[0];
S++;
X.push_back(0);
Y.push_back(0);
int l = v.size();
int old = l;
while( (l & (l - 1)) != 0 )
l++;
int mns = l - old;
newv.clear();
newv.resize(l);
pos.clear();
pos.resize(l);
where.clear();
where.resize(l);
int lg = 0;
for(lg = 0; (1 << lg) < l; lg++);
for(int i = 0; i < l; i++)
{
int msk = i;
int rmsk = 0;
for(int j = 0; j < lg; j++)
if((msk >> j) & 1)
rmsk |= (1 << (lg - j - 1));
pos[rmsk] = i;
where[i] = rmsk;
}
vector<int> poss;
for(int i = mns; i < l; i++)
poss.push_back(pos[i]);
sort(begin(poss), end(poss));
for(int i = 0; i < old; i++)
newv[ where[ poss[i] ] ] = v[i];
for(int i = 0; i < mns; i++)
newv[i] = -S;
return make_switch(0, l - 1, S);
}
void create_circuit(int M, vector<int> A)
{
vector< vector<int> > v;
v.resize(M + 2);
int lst = 0;
for(int i = 0; i < A.size(); i++)
{
v[lst].push_back(A[i]);
lst = A[i];
}
v[lst].push_back(0);
vector<int> ex;
ex.resize(M + 1);
X.clear(), Y.clear();
S = 0;
for(int i = 0; i <= M; i++)
{
int l = v[i].size();
ex[i] = make_switch(v[i]);
}
answer(ex, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int i = 0; i < A.size(); i++)
| ~~^~~~~~~~~~
doll.cpp:122:13: warning: unused variable 'l' [-Wunused-variable]
122 | int l = v[i].size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
42 ms |
6296 KB |
Output is correct |
3 |
Correct |
29 ms |
5164 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
16 ms |
3788 KB |
Output is correct |
6 |
Correct |
54 ms |
7752 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
42 ms |
6296 KB |
Output is correct |
3 |
Correct |
29 ms |
5164 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
16 ms |
3788 KB |
Output is correct |
6 |
Correct |
54 ms |
7752 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
64 ms |
7228 KB |
Output is correct |
9 |
Correct |
98 ms |
8620 KB |
Output is correct |
10 |
Correct |
128 ms |
11196 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
42 ms |
6296 KB |
Output is correct |
3 |
Correct |
29 ms |
5164 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
16 ms |
3788 KB |
Output is correct |
6 |
Correct |
54 ms |
7752 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
64 ms |
7228 KB |
Output is correct |
9 |
Correct |
98 ms |
8620 KB |
Output is correct |
10 |
Correct |
128 ms |
11196 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 |
136 ms |
10916 KB |
Output is correct |
15 |
Correct |
65 ms |
5784 KB |
Output is correct |
16 |
Correct |
109 ms |
8616 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
112 ms |
10660 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
4668 KB |
Output is correct |
3 |
Correct |
46 ms |
6968 KB |
Output is correct |
4 |
Correct |
65 ms |
7992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
4668 KB |
Output is correct |
3 |
Correct |
46 ms |
6968 KB |
Output is correct |
4 |
Correct |
65 ms |
7992 KB |
Output is correct |
5 |
Partially correct |
139 ms |
11108 KB |
Output is partially correct |
6 |
Partially correct |
178 ms |
10700 KB |
Output is partially correct |
7 |
Partially correct |
121 ms |
10748 KB |
Output is partially correct |
8 |
Partially correct |
102 ms |
9992 KB |
Output is partially correct |
9 |
Correct |
90 ms |
6008 KB |
Output is correct |
10 |
Correct |
153 ms |
9748 KB |
Output is correct |
11 |
Partially correct |
99 ms |
8656 KB |
Output is partially correct |
12 |
Partially correct |
71 ms |
5912 KB |
Output is partially correct |
13 |
Partially correct |
81 ms |
7072 KB |
Output is partially correct |
14 |
Partially correct |
94 ms |
7148 KB |
Output is partially correct |
15 |
Partially correct |
85 ms |
7440 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
460 KB |
Output is partially correct |
17 |
Partially correct |
68 ms |
5636 KB |
Output is partially correct |
18 |
Partially correct |
72 ms |
6240 KB |
Output is partially correct |
19 |
Partially correct |
71 ms |
5608 KB |
Output is partially correct |
20 |
Partially correct |
106 ms |
8464 KB |
Output is partially correct |
21 |
Partially correct |
103 ms |
8344 KB |
Output is partially correct |
22 |
Partially correct |
128 ms |
7996 KB |
Output is partially correct |