Submission #312076

#TimeUsernameProblemLanguageResultExecution timeMemory
312076kylych03Mechanical Doll (IOI18_doll)C++14
10 / 100
6 ms4988 KiB
#include "doll.h" #include <bits/stdc++.h> //#include "grader.cpp" using namespace std; int vis[200002]; vector <int> x,y; vector <int> vec[200002]; int cnt = 1; void rec(vector <int > v){ vector <int> v1, v2; if(v.size()==0) return ; if(v.size()==1){ x.push_back(-cnt); y.push_back(v[0]); cnt++; return ; } if(v.size()==2){ x.push_back(v[0]); y.push_back(v[1]); cnt++; return ; } if(v.size()%2==1){ v.insert(v.begin() , -cnt); } for(int i = 0; i < v.size(); i++){ if(i%2==0) v1.push_back(v[i]); else v2.push_back(v[i]); } int p = cnt; cnt++; x.push_back(-cnt); y.push_back(-cnt); rec(v1); y[p-1]=-cnt; rec(v2); } void create_circuit(int M, std::vector<int> A) { int N = A.size(); if(N==16){ vector<vector<int> > qs(M + 1); for(int i = 0; i < N; ++i) { qs[A[i]].push_back(i); } int bits = 1; while((1 << bits) < N) ++bits; vector<int> C(M + 1, -1); C[0] = A[0]; vector<int> X((1 << bits) - 1, -1), Y((1 << bits) - 1, -1); for(int i = 1; i < 1 << (bits - 1); ++i) { X[i - 1] = -(2 * i); Y[i - 1] = -(2 * i + 1); } vector<int> perm; for(int i = 1 << bits; i < 2 << bits; ++i) { perm.push_back(i); } sort(perm.begin(), perm.end(), [&](int i, int j) { for(int k = 0; k < bits; ++k) { if(((i >> k) & 1) != ((j >> k) & 1)) { return ((i >> k) & 1) < ((j >> k) & 1); } } return false; }); for(int i = 0; i < 1 << bits; ++i) { int tar = i - ((1 << bits) - N); if(tar < 0) tar = -1; else if(i != ((1 << bits) - 1)) tar = A[tar + 1]; else tar = 0; if(perm[i] % 2 == 0) { X[perm[i] / 2 - 1] = tar; } else { Y[perm[i] / 2 - 1] = tar; } } answer(C, X, Y); return ; } std::vector<int> C(M + 1); vector <int> X, Y; for(int i = 0; i<M+1; i++){ C[i]=0; } C[0]=A[0]; A.push_back(0); for(int i = 0 ; i < N; i++){ vec[A[i]].push_back(A[i+1]); } for(int i = 1 ; i <=M ;i++){ if(vec[i].size()>0){ C[i] = -cnt; rec( vec[i]); } } for(int i = 0; i <C.size(); i++) cout << C[i]<<" "; cout << endl; for(int i = 0; i <x.size(); i++) cout << x[i]<<" "<<y[i]<<endl; cout << endl; answer(C, x, y); }

Compilation message (stderr)

doll.cpp: In function 'void rec(std::vector<int>)':
doll.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:105:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |    for(int i = 0; i <C.size(); i++)
      |                   ~~^~~~~~~~~
doll.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i = 0; i <x.size(); i++)
      |                    ~~^~~~~~~~~
#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...