Submission #75400

# Submission time Handle Problem Language Result Execution time Memory
75400 2018-09-09T15:07:01 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;
}

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

  vector<int> b = AdjList[curTrigger];

  vector<int> a;
  int i;
  for(i = 0; i < b.size() && i < dummies; i++) {
    a.push_back(globalCurSwitch);
    a.push_back(b[i]);
  }
  for(; i < b.size(); i++)
    a.push_back(b[i]);
  for(; i < dummies; i++)
    a.push_back(globalCurSwitch);

  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:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(i = 0; i < b.size() && i < dummies; i++) {
      |              ~~^~~~~~~~~~
doll.cpp:60:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(; i < b.size(); i++)
      |         ~~^~~~~~~~~~
doll.cpp:69:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for(int i = 0; i < b.size(); i+=2) {
      |                  ~~^~~~~~~~~~
doll.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i = 1; i < b.size(); i+=2) {
      |                  ~~^~~~~~~~~~
doll.cpp:82:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   82 |   if(X.size() <= abs(curSwitch)-1) X.resize(abs(curSwitch)), Y.resize(abs(curSwitch));
      |      ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp:68:7: warning: variable 'nextDummies' set but not used [-Wunused-but-set-variable]
   68 |   int nextDummies = 0;
      |       ^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:93:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     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 4884 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 -