Submission #503599

#TimeUsernameProblemLanguageResultExecution timeMemory
503599snasibov05Mechanical Doll (IOI18_doll)C++14
2 / 100
48 ms8348 KiB
#include "doll.h" #include <queue> using namespace std; void create_circuit(int m, vector<int> a) { int n = a.size(); vector<vector<int>> to(m+1); to[0].push_back(a[0]); to[a[n-1]].push_back(0); for (int i = 0; i < n-1; ++i){ to[a[i]].push_back(a[i+1]); } vector<int> x, y; vector<bool> state; state.push_back(true); x.push_back(0); y.push_back(0); int cur = -1; vector<int> c(m+1); for (int i = 0; i <= m; ++i){ int k = 0, b = 1; while (to[i].size() > b) b *= 2, k++; if (k == 0){ if (to[i].empty()) c[i] = 0; else c[i] = to[i][0]; continue; } int src = cur; int mx = cur - b + 2; c[i] = cur--; queue<int> q; q.push(cur+1); while (!q.empty()){ state.push_back(true); q.pop(); if (cur < mx) { x.push_back(0); y.push_back(0); continue; } x.push_back(cur--); y.push_back(cur--); q.push(x.back()); q.push(y.back()); } int rem = b - (int)to[i].size(); for (int j = 0; j < to[i].size() - rem; ++j){ int pos = src; for (int l = 0; l < b-1; ++l) { if (state[-pos]) { state[-pos] = false; pos = x[-pos]; } else{ state[-pos] = true; pos = y[-pos]; } } if (state[-pos]) { state[-pos] = false; x[-pos] = to[i][j]; } else{ state[-pos] = true; y[-pos] = to[i][j]; } } for (int j = to[i].size() - rem; j < to[i].size(); ++j){ int pos = src; for (int l = 0; l < b-1; ++l) { if (state[-pos]) { state[-pos] = false; pos = x[-pos]; } else{ state[-pos] = true; pos = y[-pos]; } } if (state[-pos]) { state[-pos] = false; x[-pos] = src; } else{ state[-pos] = true; y[-pos] = src; } pos = src; for (int l = 0; l < b-1; ++l) { if (state[-pos]) { state[-pos] = false; pos = x[-pos]; } else{ state[-pos] = true; pos = y[-pos]; } } if (state[-pos]) { state[-pos] = false; x[-pos] = to[i][j]; } else{ state[-pos] = true; y[-pos] = to[i][j]; } } } answer(c, x, y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:26:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |         while (to[i].size() > b) b *= 2, k++;
      |                ~~~~~~~~~~~~~^~~
doll.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = 0; j < to[i].size() - rem; ++j){
      |                         ~~^~~~~~~~~~~~~~~~~~~~
doll.cpp:75:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for (int j = to[i].size() - rem; j < to[i].size(); ++j){
      |                                          ~~^~~~~~~~~~~~~~
#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...