Submission #1246508

#TimeUsernameProblemLanguageResultExecution timeMemory
12465082008Message (IOI24_message)C++20
Compilation error
0 ms0 KiB
#include "message.h"
using namespace std;
#include<bits/stdc++.h>

string binary15(int n) {
  int clone = n;
  string bin;
  bin.push_back(clone>7); clone=clone%8;
  bin.push_back(clone>3); clone=clone%4;
  bin.push_back(clone>1); clone=clone%2;
  bin.push_back(clone>0);
  return bin;
}

string binary1023(int n) {
  int clone = n;
  string bin;
  bin.push_back(clone>511); clone=clone%512;
  bin.push_back(clone>255); clone=clone%256;
  bin.push_back(clone>127); clone=clone%128;
  bin.push_back(clone>63); clone=clone%64;
  bin.push_back(clone>31); clone=clone%32;
  bin.push_back(clone>15); clone=clone%16;
  bin.push_back(clone>7); clone=clone%8;
  bin.push_back(clone>3); clone=clone%4;
  bin.push_back(clone>1); clone=clone%2;
  bin.push_back(clone>0);
  return bin;
}

void send_message(std::vector<bool> M, std::vector<bool> C) {
  std::vector<bool> A(31, 0);
  const vector<bool> zero(31,0);
  const vector<bool> one(31,1);
  int S=(int)M.size();
  int firstsafe=0;
  for (int i=0; C[i]==1; i++) {
    firstsafe++;
  }
  for (int i=0; i<4; i++) {
    if (binary15(firstsafe)[i] == 0) {
      A == zero;
    } else {
      A == one;
    }
    send_packet(A);
  }
  int cb=0;
  for (int i=0; i<31; i++) {
    A == zero;
    if (C[i]==0 && cb<10) {
      A[i]=binary1023(M)[cb]; cb++;
    }
  }
  send_packet(A);
  int counting=0;
  for (int t=0; t<31; t++) {
    A == zero;
    A[firstsafe]=C[t];
    for (int i=firstsafe+1; i<31; i++) {
      if (C[i]==0 && counting<S) {
        A[i]=M[counting]; counting++;
      }
    }
    send_packet(A);
  }
  if (counting < S-1) {
    for (int i=0; (16*i)+counting<S-1; i++) {
      A==zero;
      for (int j=0; j<30; j++) {
        if (C[j]==0 && counting<S) {
          A[i]=M[counting]; counting++;
        }
      }
      send_packet(A);
    }
  }
}

bool read(vector<bool> V) {
  int countzero=0, countone=0, thesize=V.size();
  for (int i=0; i<thesize; i++) {
    if (V[i] == 0) {
      countzero++;
    } else {
      countone++;
    }
  }
  return countone>countzero;
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
  int rsize = R.size();
  int safe=0;
  vector<bool>solution;
  if (read(R[0]) == 1) {
    safe+=8;
  }
  if (read(R[1]) == 1) {
    safe+=4;
  }
  if (read(R[2]) == 1) {
    safe+=2;
  }
  if (read(R[3]) == 1) {
    safe+=1;
  }
  vector<bool> truth(31,1);
  for (int i=5; i<36; i++) {
    truth[i-5]=R[i][safe];
  }
  vector<int> safeones;
  for (int i=safe; i<31; i++) {
    if (truth[i] == 0) {
      safeones.push_back[i];
    }
  }
  int lenght=1;
  for (int i=0; i<10; i++) {
    lenght+=(1-truth[i])*(pow(2,9-i));
  }
  for (int i=5; i<36; i++) {
    for (int j=1; j<16; j++) {
      solution.push_back(R[i][truth[j]]);
    }
  }
  for (int i=36; i<rsize; i++) {
    for (int j=0; j<16; j++) {
      if (solution.size()<lenght) {
        solution.push_back(R[i][truth[j]]);
      }
    }
  }
  return solution;
}

Compilation message (stderr)

message.cpp: In function 'void send_message(std::vector<bool>, std::vector<bool>)':
message.cpp:52:23: error: cannot convert 'std::vector<bool>' to 'int'
   52 |       A[i]=binary1023(M)[cb]; cb++;
      |                       ^
      |                       |
      |                       std::vector<bool>
message.cpp:15:23: note:   initializing argument 1 of 'std::string binary1023(int)'
   15 | string binary1023(int n) {
      |                   ~~~~^
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:115:25: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  115 |       safeones.push_back[i];
      |                         ^