#include<bits/stdc++.h>
#include "doll.h"
#define MAXN 200007
using namespace std;
int m,power,n;
int a[MAXN],s;
int lt[MAXN],rt[MAXN];
vector<int> from,to,c;
int rev(int x){
int res=0;
for(int i=1;i<power;i*=2){
res*=2; res+=x%2;
x/=2;
}
return res;
}
void build(int v,int l,int r,int num){
if(l+1==r){
num*=2;
if(rev(num)<n)lt[v]=a[rev(num)];
else if(rev(num)==power-1)lt[v]=0;
else lt[v]=-1;
num++;
if(rev(num)<n)rt[v]=a[rev(num)];
else if(rev(num)==power-1)rt[v]=0;
else rt[v]=-1;
}else{
int tt=(l+r)/2;
build(2*v,l,tt,2*num);
build(2*v+1,tt+1,r,2*num+1);
lt[v]=-2*v; rt[v]=-2*v-1;
}
}
void create_circuit(int M, vector<int> A){
m=M; n=int(A.size());
for(int i=0;i<n;i++){
a[i]=A[i];
}
power=1;
while(power<n+1)power*=2;
build(1,0,power-1,0);
for(int i=0;i<=m;i++)c.push_back(-1);
for(int i=1;i<=power-1;i++){
if(lt[i]>0)n--;
if(rt[i]>0)n--;
from.push_back(lt[i]);
to.push_back(rt[i]);
}
if(n!=0)cout<<1/0;
answer(c,from,to);
}
/*
int main(){
create_circuit(4, {1, 2, 1,3,2,4,3,1,2});
}
*/
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:60:20: warning: division by zero [-Wdiv-by-zero]
60 | if(n!=0)cout<<1/0;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Incorrect |
58 ms |
10684 KB |
wrong motion |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Incorrect |
58 ms |
10684 KB |
wrong motion |
3 |
Halted |
0 ms |
0 KB |
- |