#include "message.h"
#include <iostream>
#define all(a) a.begin(), a.end()
#define popcount(x) __builtin_popcountll(x)
using namespace std;
void send_message(vector<bool> message, vector<bool> C) {
for (int i = 0; i < 30; i++) {
send_packet(vector<bool>(31, C[i]));
}
vector<int> pos;
for (int i = 0; i < 31; i++) if (C[i] == 0)
pos.push_back(i);
for (int i = 0; i < message.size(); i += 16) {
vector<bool> packet(31);
int j = i;
for (int p : pos) if (j < message.size()) {
packet[p] = message[j++];
}
send_packet(packet);
}
vector<bool> packet(31);
for (int i = 0; i < 4; i++) {
packet[pos[i]] = (message.size() % 16) >> i & 1;
}
send_packet(packet);
}
vector<bool> receive_message(vector<vector<bool>> packets) {
vector<int> pos;
for (int i = 0; i < 30; i++) {
int cnt[2] = {};
for (auto b : packets[i]) {
cnt[b]++;
}
if (cnt[0] > cnt[1]) {
pos.push_back(i);
}
}
if (pos.size() < 16)
pos.push_back(30);
vector<bool> message;
for (int i = 30; i < packets.size() - 2; i++) {
for (int j : pos) {
message.push_back(packets[i][j]);
}
}
int to_read = 0;
for (int i = 0; i < 4; i++) {
to_read |= packets.back()[pos[i]] << i;
}
if (to_read == 0) to_read = 16;
for (int i = 0; i < to_read; i++) {
message.push_back(packets[packets.size() - 2][pos[i]]);
}
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... |