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 <iostream>
#include <vector>
#include "doll.h"
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
using ll=int;
int const nmax = 400000;
using namespace std;
ll leftp[nmax+1];
int rightp[nmax+1];
int cng[nmax+1];
int switches=0,added=0;
ll creategraph(ll nodes,ll realnodes){
if(realnodes==0){
return -1;
}
if(nodes==1){
return (added++);
}
ll centr=-(++switches);
leftp[-centr]=creategraph(nodes/2,realnodes-MIN(nodes/2,realnodes));
rightp[-centr]=creategraph(nodes/2,MIN(nodes/2,realnodes));
return centr;
}
std::vector<int>dest;
int real[nmax+1];
ll dfs(ll node){
if(node>=0){
return node;
}else {
cng[-node]=(!cng[-node]);
if(cng[-node]==1){
dfs(leftp[-node]);
}else dfs(rightp[-node]);
}
}
void create_circuit(int M,vector<int>A){
vector<int>C(M+1);
C[0]=-1;
for(int i=1;i<=M;i++)
{
C[i]=-1;
}
for(ll i=0;i<A.size();i++)
{
dest.push_back(A[i]);
}
dest.push_back(0);
int nodes=1;
while(nodes<dest.size()){
nodes*=2;
}
creategraph(nodes,dest.size());
for(int i=0;i<dest.size();i++)
{
real[dfs(-1)]=dest[i];
}
vector<int>X(switches),Y(switches);
for(ll k=1;k<=switches;k++)
{
X[k-1]=leftp[k];
Y[k-1]=rightp[k];
if(X[k-1]>=0){
X[k-1]=real[X[k-1]];
}
if(Y[k-1]>=0){
Y[k-1]=real[Y[k-1]];
}
}
answer(C,X,Y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:43:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(ll i=0;i<A.size();i++)
| ~^~~~~~~~~
doll.cpp:49:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | while(nodes<dest.size()){
| ~~~~~^~~~~~~~~~~~
doll.cpp:53:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<dest.size();i++)
| ~^~~~~~~~~~~~
doll.cpp: In function 'll dfs(ll)':
doll.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
# | 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... |