#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
/*
void answer(vector<int> C,vector<int> x,vector<int> y)
{
cout<<"C: ";for(auto k:C)cout<<k<<" ";cout<<endl;
int SZ=x.size();
cout<<"switches "<<endl;
for(int i=0;i<SZ;i++)
{
cout<<x[i]<<" "<<y[i]<<endl;
}
cout<<"---"<<endl;
//exit(0);
}
*/
vector<int> x,y;
vector<int> order;
bool state[1'000'000];
int open;
void solve(int run,int where)
{
//cout<<"solve "<<run<<" "<<where<<endl;
where=-where;
if(where>=open/2)
{
if(run<order.size())
{
if(state[where-1]==0)
{
x[where-1]=order[run];
state[where-1]=!state[where-1];
}
else
{
y[where-1]=order[run];
state[where-1]=!state[where-1];
}
return;
}
if(run==open-1)
{
y[where-1]=0;
return;
}
state[where-1]=!state[where-1];
return;
}
if(state[where-1]==0)
{
state[where-1]=1;
solve(run,x[where-1]);
}
else
{
state[where-1]=0;
solve(run,y[where-1]);
}
}
void create_circuit(int M, vector<int> A)
{
vector<int> C={};
for(int i=0;i<=M;i++)
C.push_back(-1);
C[0]=A[0];
A.erase(A.begin(),A.begin()+1);
open=2;
while(open<=A.size())open=open*2;
for(int i=1;i<open;i++)
{
x.push_back(-1);
y.push_back(-1);
}
for(int i=1;i<open/2;i++)
{
x[i-1]=-(2*i);
y[i-1]=-(2*i+1);
}
order=A;
for(int i=0;i<open;i++)
solve(i,-1);
int sz=x.size();
for(int i=0;i<x.size();i++)
{
int where_le=-x[i]-1;
int where_ri=-y[i]-1;
if(where_le<=0||where_ri<=0)continue;
//cout<<i<<" "<<where_le<<" "<<where_ri<<endl;
if(y[where_le]==-1&&y[where_ri]==-1)
{
//cout<<where_le<<" and "<<where_ri<<" are useless"<<endl;
x[i]=x[where_le];
y[i]=x[where_ri];
sz=sz-2;
}
}
set<int> nums={1};
for(auto k:x)
if(k<0)nums.insert(-k);
for(auto k:y)
if(k<0)nums.insert(-k);
map<int,int> seen={};
int id=0;
for(auto k:nums)
{
id--;
seen[-k]=id;
//cout<<-k<<" -> "<<id<<endl;
}
vector<int> x_={},y_={};
for(int i=0;i<open-1;i++)
{
if(nums.count(i+1))
{
if(x[i]<0)x_.push_back(seen[x[i]]);
else x_.push_back(x[i]);
if(y[i]<0)y_.push_back(seen[y[i]]);
else y_.push_back(y[i]);
}
}
/*
answer(C,x,y);
cout<<"---"<<endl;
*/
answer(C,x_,y_);
}
/*
int main()
{
//create_circuit(4, {1, 2, 1,3});
create_circuit(1,{1,1,1,1,1});
}
*/
Compilation message
doll.cpp: In function 'void solve(int, int)':
doll.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(run<order.size())
| ~~~^~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:79:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | while(open<=A.size())open=open*2;
| ~~~~^~~~~~~~~~
doll.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int i=0;i<x.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 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 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |