Submission #75735

#TimeUsernameProblemLanguageResultExecution timeMemory
75735KieranHorganMechanical Doll (IOI18_doll)C++17
100 / 100
157 ms11672 KiB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> A, X, Y, C;

int nextSwitch = -1;
int recurseThroughTree(vector<int> b) {
  if(b.size() == 1) return b[0];

  int curSwitch = nextSwitch--;

  vector<int> a;
  for(int i = 0; i < b.size(); i+=2)
    a.push_back(b[i]);
  int l = a.back() == -1 ? -1 : recurseThroughTree(a);

  a.clear();
  for(int i = 1; i < b.size(); i+=2)
    a.push_back(b[i]);
  int r = a.back() == -1 ? -1 : recurseThroughTree(a);

  if(X.size() <= abs(curSwitch)-1) X.resize(abs(curSwitch)), Y.resize(abs(curSwitch));
  X[abs(curSwitch)-1] = l;
  Y[abs(curSwitch)-1] = r;

  return curSwitch;
}

int getDest(int x, int bits) {
  int res = 0;
  for(int i = 0; i < bits; i++)
    if(x & (1<<i))
      res |= 1<<(bits-1-i);
  return res;
}

void create_circuit(int M, vector<int> A_) {
  int N = A_.size();
  A = A_;
  A.push_back(0);
  C.assign(M+1, -1);

  int dummies = 0;
  while(__builtin_popcount(A.size()+dummies) != 1)
    dummies++;

  vector<int> b;
  int i, j;
  for(i = 0, j = 0; j < A.size() + dummies; j++) {
    if(i >= A.size() || getDest(j, __builtin_ctz(A.size()+dummies)) < dummies) b.push_back(-1);
    else b.push_back(A[i++]);
  }
  recurseThroughTree(b);

  answer(C, X, Y);
}

Compilation message (stderr)

doll.cpp: In function 'int recurseThroughTree(std::vector<int>)':
doll.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for(int i = 0; i < b.size(); i+=2)
      |                  ~~^~~~~~~~~~
doll.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   for(int i = 1; i < b.size(); i+=2)
      |                  ~~^~~~~~~~~~
doll.cpp:23:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |   if(X.size() <= abs(curSwitch)-1) X.resize(abs(curSwitch)), Y.resize(abs(curSwitch));
      |      ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(i = 0, j = 0; j < A.size() + dummies; j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~
doll.cpp:51:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     if(i >= A.size() || getDest(j, __builtin_ctz(A.size()+dummies)) < dummies) b.push_back(-1);
      |        ~~^~~~~~~~~~~
doll.cpp:39:7: warning: unused variable 'N' [-Wunused-variable]
   39 |   int N = A_.size();
      |       ^
#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...