#include "message.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void send_message(vector<bool> M, vector<bool> C) {
for (int i = 0;i < 30;i++) {
vector<bool> A(31, C[i]);
send_packet(A);
}
int n = M.size();
{
vector<bool> A(31, 0);
int now = 0;
for (int j = 0;j < 31;j++) {
if (C[j] == 0) {
A[j] = (n >> now) & 1;
now++;
}
}
send_packet(A);
}
int now = 0;
while (now < n) {
vector<bool> A(31, 0);
for (int j = 0;j < 31;j++) {
if (C[j] == 0) {
A[j] = M[now++];
if (now == n) break;
}
}
send_packet(A);
}
}
vector<bool> receive_message(vector<vector<bool>> R) {
vector<bool> ans;
vector<bool> C(31, 0);
for (int i = 0;i < 30;i++) {
int cnt0 = 0, cnt1 = 0;
for (bool x : R[i]) {
if (x) cnt1++;
else cnt0++;
}
C[i] = cnt1 > cnt0;
if (C[i]) C[30] = !C[30];
}
int n = 0;
{
int now = 0;
for (int j = 0;j < 31;j++) {
if (C[j] == 0) {
n += R[30][j] << now;
now++;
}
}
}
for (int i = 31;i < (int)R.size();i++) {
for (int j = 0;j < 31;j++) {
if (C[j] == 0) {
ans.push_back(R[i][j]);
if ((int)ans.size() == n) break;
}
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |