Submission #75409

# Submission time Handle Problem Language Result Execution time Memory
75409 2018-09-09T15:33:02 Z KieranHorgan Mechanical Doll (IOI18_doll) C++17
0 / 100
5 ms 4940 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> A, X, Y, C;
int dep[200];
int nextSwitch = -1;
vector<int> AdjList[200005];

int globalCurSwitch;

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

  vector<int> a;

  a.clear();
  int nextDummies = 0;
  for(int i = 0; i < b.size(); i+=2) {
    if(b[i] == globalCurSwitch) nextDummies++;
    a.push_back(b[i]);
  }
  int l;
  if(nextDummies == a.size()) {
    l = globalCurSwitch;
  } else {
    l = recurseThroughTree(a);
  }

  a.clear();
  for(int i = 1; i < b.size(); i+=2) {
    if(b[i] == globalCurSwitch) nextDummies++;
    a.push_back(b[i]);
  }
  int r = 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;
}

bitset<200005> is;

void buildTree(int curTrigger, int curSwitch) {
  globalCurSwitch = curSwitch;
  int x = AdjList[curTrigger].size();
  int dummies = 0;
  while(__builtin_popcount(x+dummies) != 1)
    dummies++;

  // cerr << curTrigger << ": " << x+dummies << " " << dummies << endl;
  vector<int> b = AdjList[curTrigger];

  vector<int> pos, posCop;
  if(pos.size() != dummies)
    pos = {0};
  for(int i = x+dummies; i > 1; i /= 2) {
    if(pos.size() == dummies)
      break;
    posCop = pos;
    for(auto x: posCop) {
      pos.push_back(x+(i/2));
      if(pos.size() == dummies)
        break;
    }
    // cerr << i << " " << pos.size() << endl;
  }
  is.reset();
  for(auto x: pos)
    is[x]=1;
  pos.clear();
  posCop.clear();

  vector<int> a;
  for(int j = 0, i = 0; j < x+dummies; j++) {
    if(is[j]) a.push_back(globalCurSwitch);
    else a.push_back(b[i++]);
  }

  b = a;

  a.clear();
  int nextDummies = 0;
  for(int i = 0; i < b.size(); i+=2) {
    a.push_back(b[i]);
  }
  int l = recurseThroughTree(a);

  a.clear();
  nextDummies = 0;
  for(int i = 1; i < b.size(); i+=2) {
    a.push_back(b[i]);
  }
  int r = recurseThroughTree(a);
  a.clear();

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

void create_circuit(int M, vector<int> A_) {
  A = A_;
  int N = A.size();

  if(!A.empty()) {
    AdjList[0].push_back(A[0]);
    for(int i = 0; i+1 < A.size(); i++) {
      AdjList[A[i]].push_back(A[i+1]);
    }
    AdjList[A.back()].push_back(0);
  }

  C.assign(M+1, 0);
  for(int i = 0; i <= M; i++) {
    if(AdjList[i].empty()) {
    } else if(AdjList[i].size() == 1) {
      C[i] = AdjList[i][0];
    } else {
      C[i] = nextSwitch--;
      buildTree(i, C[i]);
      // for(int j = C[i]; j > nextSwitch; j--) {
        // cerr << j << ": " << X[abs(j)-1] << " " << Y[abs(j)-1] << endl;
      // }
    }
  }

  double score;
  int S = X.size();
  // cerr << S << " " << N+log2(N) << endl;
  if(S <= N + log2(N)) score = 1;
  else if(S <= 2*N) score = 0.5 + 0.4*((2*N - S)/(N-log2(N)))*((2*N - S)/(N-log2(N)));
  else score = 0;
  score *= 100;

  cout << "Score: " << setprecision(7) << fixed << score << "\t";
  answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'int recurseThroughTree(std::vector<int>)':
doll.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for(int i = 0; i < b.size(); i+=2) {
      |                  ~~^~~~~~~~~~
doll.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   if(nextDummies == a.size()) {
      |      ~~~~~~~~~~~~^~~~~~~~~~~
doll.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(int i = 1; i < b.size(); i+=2) {
      |                  ~~^~~~~~~~~~
doll.cpp:38:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |   if(X.size() <= abs(curSwitch)-1) X.resize(abs(curSwitch)), Y.resize(abs(curSwitch));
      |      ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void buildTree(int, int)':
doll.cpp:58:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |   if(pos.size() != dummies)
      |      ~~~~~~~~~~~^~~~~~~~~~
doll.cpp:61:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |     if(pos.size() == dummies)
      |        ~~~~~~~~~~~^~~~~~~~~~
doll.cpp:66:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |       if(pos.size() == dummies)
      |          ~~~~~~~~~~~^~~~~~~~~~
doll.cpp:87:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for(int i = 0; i < b.size(); i+=2) {
      |                  ~~^~~~~~~~~~
doll.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for(int i = 1; i < b.size(); i+=2) {
      |                  ~~^~~~~~~~~~
doll.cpp:100:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |   if(X.size() <= abs(curSwitch)-1) X.resize(abs(curSwitch)), Y.resize(abs(curSwitch));
      |      ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp:86:7: warning: variable 'nextDummies' set but not used [-Wunused-but-set-variable]
   86 |   int nextDummies = 0;
      |       ^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:111:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for(int i = 0; i+1 < A.size(); i++) {
      |                    ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4940 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4940 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4940 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -