#include "message.h"
using namespace std;
#include<bits/stdc++.h>
#include<cmath>
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;
}
int roof(float f) {
int floor = f;
if (f==floor) {
return f;
} else {
return f+1;
}
}
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();
vector<int>spaces;
for (int i=0; i<31; i++) {
if (C[i]==0) {
A=zero;
spaces.push_back(i);
} else {
A=one;
}
send_packet(A);
}
A=zero;
for (int i=0; i<10; i++) {
A[spaces[i]]=binary1023(S-1)[i];
}
send_packet(A);
int times = roof(S/16), counting = 0;
for (int i=0; i<times; i++) {
A=zero;
for (int j=0; j<16; j++) {
if (counting < S) {
A[spaces[j]]=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();
vector<int>safe;
vector<bool>solution;
int lenght=0, sofar=0;
for (int i=0; i<31; i++) {
if (read(R[i])==1) {
safe.push_back(i);
}
}
for (int i=0; i<10; i++) {
lenght+=R[31][safe[i]]*pow(2,9-i);
}
for (int i=32; i<rsize; i++) {
for (int j=0; j<16; j++) {
if (sofar<lenght) {
solution.push_back(R[i][safe[j]]);
sofar++;
}
}
}
return solution;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |