Submission #542818

#TimeUsernameProblemLanguageResultExecution timeMemory
542818Sho10Mechanical Doll (IOI18_doll)C++17
0 / 100
162 ms262144 KiB
#include "doll.h" #include <iostream> #include <vector> #define MIN(a, b) (((a) < (b)) ? (a) : (b)) int const nmax = 400000; int leftp[nmax+1]; int rightp[nmax+1]; int cng[nmax+1]; int switches=0,added=0; int creategraph(int nodes, int realnodes){ if(realnodes == 0) return -1; if(nodes == 1) return (added++); int central = -(++switches); leftp[-central] = creategraph(nodes / 2, realnodes - MIN(nodes / 2, realnodes)); rightp[-central] = creategraph(nodes / 2, MIN(nodes / 2, realnodes)); return central; } std::vector<int>dest; int real[nmax+1]; int dfs(int 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,std::vector<int>A){ std::vector<int>C(M+1); C[0]=-1; for(int i=1;i<=M;i++) { C[i]=-1; } for(int 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]; } std::vector<int>X(switches),Y(switches); for(int 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:42:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 | for(int i=0;i<A.size();i++)
      |             ~^~~~~~~~~
doll.cpp:48:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 | while(nodes<dest.size()){
      |       ~~~~~^~~~~~~~~~~~
doll.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 | for(int i=0;i<dest.size();i++)
      |             ~^~~~~~~~~~~~
doll.cpp: In function 'int dfs(int)':
doll.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...