This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int sw;
vector<int> nxt[N];
int x[N],y[N];
vector<int> ls;
void build(int l,int r,int idx)
{
x[idx] = -idx*2,y[idx] = -(idx*2+1);
if(l+1==r) return void(ls.push_back(idx));
int m = (l+r)/2;
build(l,m,idx*2),build(m+1,r,idx*2+1);
}
void create_circuit(int m,vector<int> a)
{
int n = a.size();
vector<int> c(m+1);
a.push_back(0);
for(int i = 0;i < n;i++) nxt[a[i]].push_back(a[i+1]);
c[0] = a[0];
for(int i = 1;i <= m;i++) if(!nxt[i].empty())
{
if(nxt[i].size()==1){ c[i] = nxt[i][0]; continue; }
int depth = 0;
for(int j = 0;;j++) if((1 << j)>=nxt[i].size()){ depth = j; break; }
ls.clear();
build(0,(1 << depth)-1,1);
c[i] = -1;
for(int j = 0;j < ls.size();j++)
{
int id = j*2,ie = j*2+1,ix = 0,iy = 0;
for(int k = 0;k < depth;k++) if(id&(1 << k)) ix+=(1 << (depth-1-k));
for(int k = 0;k < depth;k++) if(ie&(1 << k)) iy+=(1 << (depth-1-k));
if(ix<(1 << depth)-nxt[i].size()) x[ls[j]] = -1;
else x[ls[j]] = nxt[i][ix-((1 << depth)-nxt[i].size())];
if(iy<(1 << depth)-nxt[i].size()) y[ls[j]] = -1;
else y[ls[j]] = nxt[i][iy-((1 << depth)-nxt[i].size())];
}
sw = (1 << depth);
}
vector<int> sx,sy;
for(int i = 1;i <= sw;i++) sx.push_back(x[i]),sy.push_back(y[i]);
answer(c,sx,sy);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:31:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int j = 0;;j++) if((1 << j)>=nxt[i].size()){ depth = j; break; }
| ~~~~~~~~^~~~~~~~~~~~~~~
doll.cpp:35:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int j = 0;j < ls.size();j++)
| ~~^~~~~~~~~~~
doll.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(ix<(1 << depth)-nxt[i].size()) x[ls[j]] = -1;
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
doll.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(iy<(1 << depth)-nxt[i].size()) y[ls[j]] = -1;
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |