Submission #75317

# Submission time Handle Problem Language Result Execution time Memory
75317 2018-09-09T08:24:27 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 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 = recurseThroughTree(a);
  a.clear();
  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;

  return curSwitch;
}

void buildTree(int curTrigger, int curSwitch) {
  int last = AdjList[curTrigger].back();
  AdjList[curTrigger].pop_back();
  while(__builtin_popcount(AdjList[curTrigger].size()+1) != 1) AdjList[curTrigger].push_back(curSwitch);
  AdjList[curTrigger].push_back(last);

  vector<int> a;
  for(int i = 0; i < AdjList[curTrigger].size(); i+=2)
    a.push_back(AdjList[curTrigger][i]);
  int l = recurseThroughTree(a);
  a.clear();
  for(int i = 1; i < AdjList[curTrigger].size(); i+=2)
    a.push_back(AdjList[curTrigger][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;
}

int cnt[20];
int buildPerfect(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 = recurseThroughTree(a);
  a.clear();
  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;

  return curSwitch;
}

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

  if(N == 16) {
    C.assign(M+1, -1);
    C[0] = A[0];
    A.erase(A.begin());
    A.push_back(0);
    buildPerfect(A);
  } else {
    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]);
      }
    }
  }

  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:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   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 buildTree(int, int)':
doll.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i = 0; i < AdjList[curTrigger].size(); i+=2)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
doll.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int i = 1; i < AdjList[curTrigger].size(); i+=2)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
doll.cpp:45:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |   if(X.size() <= abs(curSwitch)-1) X.resize(abs(curSwitch)), Y.resize(abs(curSwitch));
      |      ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'int buildPerfect(std::vector<int>)':
doll.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int i = 0; i < b.size(); i+=2)
      |                  ~~^~~~~~~~~~
doll.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int i = 1; i < b.size(); i+=2)
      |                  ~~^~~~~~~~~~
doll.cpp:64:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |   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:84:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |       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 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 -