#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
const int N = 2e5 + 10;
int n , m;
vector <int> C , X , Y , adj[N];
int Rev(int x , int cnt)
{
int res = 0;
for(int i = 0 ; i < cnt ; i++) if((x >> i) & 1)
res |= (1 << (cnt - i - 1));
return res;
}
int Solve(vector <int> vec , bool flg = true)
{
if(vec.size() == 1)
return vec[0];
X.push_back(0);
Y.push_back(0);
int now = X.size();
vector <int> v[2];
if(flg)
{
int tmp = 1 , cnt = 0;
while(tmp < vec.size())
{
tmp *= 2;
cnt++;
}
vector <int> fake(tmp , 0);
for(int i = 0 ; i < tmp - vec.size() ; i++)
fake[Rev(i , cnt)] = -now;
int pos = 0;
for(int i = 0 ; i < tmp ; i++) if(fake[i] != -now)
{
fake[i] = vec[pos];
pos++;
}
vec = fake;
}
/*cout << "SOLVE " << endl;
for(auto u : vec)
cout << u << " ";
cout << endl;*/
if(vec[0] < 0 && vec.back() < 0)
{
X[now - 1] = vec[0];
Y[now - 1] = vec[0];
return -now;
}
for(int i = 0 ; i < vec.size() ; i++)
v[i % 2].push_back(vec[i]);
int tmp = Solve(v[0] , 0);
X[now - 1] = tmp;
tmp = Solve(v[1] , 0);
Y[now - 1] = tmp;
return -1 * now;
}
void Build(int v)
{
if(adj[v].empty())
{
C[v] = 0;
return;
}
int tmp = Solve(adj[v]);
C[v] = tmp;
}
void create_circuit(int mm , vector <int> A)
{
n = A.size();
m = mm;
C.resize(m + 1);
adj[0].push_back(A[0]);
for(int i = 0 ; i + 1 < n ; i++)
adj[A[i]].push_back(A[i + 1]);
adj[A.back()].push_back(0);
for(int i = 0 ; i <= m ; i++)
{
Build(i);
}
/*for(int i = 0 ; i <= m ; i++)
cout << i << " -> " << C[i] << endl;
for(int i = 0 ; i < X.size() ; i++)
cout << -(i + 1) << " : " << X[i] << " " << Y[i] << endl;*/
answer(C , X , Y);
}
Compilation message
doll.cpp: In function 'int Solve(std::vector<int>, bool)':
doll.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | while(tmp < vec.size())
| ~~~~^~~~~~~~~~~~
doll.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0 ; i < tmp - vec.size() ; i++)
| ~~^~~~~~~~~~~~~~~~~~
doll.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0 ; i < vec.size() ; i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
16 ms |
9308 KB |
Output is correct |
3 |
Correct |
14 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
7 ms |
6164 KB |
Output is correct |
6 |
Correct |
22 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
16 ms |
9308 KB |
Output is correct |
3 |
Correct |
14 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
7 ms |
6164 KB |
Output is correct |
6 |
Correct |
22 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
35 ms |
11632 KB |
Output is correct |
9 |
Correct |
33 ms |
11892 KB |
Output is correct |
10 |
Correct |
66 ms |
14876 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
16 ms |
9308 KB |
Output is correct |
3 |
Correct |
14 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
7 ms |
6164 KB |
Output is correct |
6 |
Correct |
22 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
35 ms |
11632 KB |
Output is correct |
9 |
Correct |
33 ms |
11892 KB |
Output is correct |
10 |
Correct |
66 ms |
14876 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
68 ms |
16524 KB |
Output is correct |
15 |
Correct |
36 ms |
10776 KB |
Output is correct |
16 |
Correct |
53 ms |
14100 KB |
Output is correct |
17 |
Correct |
1 ms |
4952 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
62 ms |
15512 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
4956 KB |
Output is partially correct |
2 |
Correct |
43 ms |
11836 KB |
Output is correct |
3 |
Partially correct |
51 ms |
13764 KB |
Output is partially correct |
4 |
Correct |
71 ms |
16304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
4956 KB |
Output is partially correct |
2 |
Correct |
43 ms |
11836 KB |
Output is correct |
3 |
Partially correct |
51 ms |
13764 KB |
Output is partially correct |
4 |
Correct |
71 ms |
16304 KB |
Output is correct |
5 |
Partially correct |
105 ms |
18448 KB |
Output is partially correct |
6 |
Partially correct |
83 ms |
18228 KB |
Output is partially correct |
7 |
Partially correct |
94 ms |
18400 KB |
Output is partially correct |
8 |
Partially correct |
79 ms |
17224 KB |
Output is partially correct |
9 |
Partially correct |
52 ms |
11920 KB |
Output is partially correct |
10 |
Partially correct |
83 ms |
15524 KB |
Output is partially correct |
11 |
Partially correct |
88 ms |
15100 KB |
Output is partially correct |
12 |
Partially correct |
44 ms |
11632 KB |
Output is partially correct |
13 |
Partially correct |
71 ms |
14064 KB |
Output is partially correct |
14 |
Partially correct |
54 ms |
13788 KB |
Output is partially correct |
15 |
Partially correct |
54 ms |
13768 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
5208 KB |
Output is partially correct |
17 |
Partially correct |
42 ms |
11308 KB |
Output is partially correct |
18 |
Partially correct |
48 ms |
11268 KB |
Output is partially correct |
19 |
Partially correct |
43 ms |
11324 KB |
Output is partially correct |
20 |
Partially correct |
64 ms |
14808 KB |
Output is partially correct |
21 |
Partially correct |
65 ms |
14464 KB |
Output is partially correct |
22 |
Partially correct |
67 ms |
14428 KB |
Output is partially correct |