#include <bits/stdc++.h>
#include "message.h"
using namespace std;
int bset(int x, int i) {
return ((x >> i) & 1);
}
const int POS = 5;
void send_message(std::vector<bool> M, std::vector<bool> C) {
vector<int> bad, good;
for(int i = 0; i < C.size(); i++) {
if(!C[i]) {
good.push_back(i);
}
}
vector<vector<bool>> header(POS, vector<bool>(31, false));
for(int i = 0; i < good.size(); i++) {
int cur = good[i];
int nxt = (i + 1 == good.size() ? 0 : good[i + 1]);
for(int j = 0; j < POS; j++) {
header[j][cur] = bset(nxt, j);
}
}
for(int i = 0; i < POS; i++) send_packet(header[i]);
for(int i = 0; i < POS; i++) send_packet(vector<bool>(31, bset(good[0], i)));
// Message length
vector<bool> msg(31, false);
for(int i = 0; i < good.size(); i++) {
msg[good[i]] = bset(M.size(), i);
}
send_packet(msg);
// Message itself
for(int i = 0; i < M.size();) {
for(int j = 0; j < good.size() && i < M.size(); i++, j++) {
msg[good[j]] = M[i];
}
send_packet(msg);
}
}
template<class T>
void debug_vec(vector<T>& t) {
// printf("DEBUG "); for(int x: t) printf("%d ", x); puts("");
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
int first = 0;
for(int i = POS; i < 2*POS; i++)
if(count(begin(R[i]), end(R[i]), true) >= 16)
first |= 1 << (i - POS);
vector<int> good;
good.push_back(first);
for(int i = 1; i < 16; i++) {
int next = 0;
for(int j = 0; j < POS; j++) {
if(R[j][good[i-1]]) {
next |= (1 << j);
}
}
good.push_back(next);
}
debug_vec(good);
// Receive message length
const int MESSAGE_LEN_POS = POS + POS;
const int MESSAGE_POS = MESSAGE_LEN_POS + 1;
int len = 0;
for(int i = 0; i < good.size(); i++) {
if(R[MESSAGE_LEN_POS][good[i]]) {
len |= (1 << i);
}
}
// printf("len=%d\n", len);
// Receive message
vector<bool> message(len, false);
for(int i = MESSAGE_POS, j = 0; i < R.size(); i++) {
for(int k = 0; k < good.size() && j < len; k++, j++) {
message[j] = R[i][good[k]];
}
}
return message;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |