#include "message.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define str string
#define vd void
#define vb vector<bool>
#define F first
#define S second
#define lbr '\n'
#define all(x) x.begin(), x.end()
const ll INF = 1E15;
vd send_message(vb m, vb c) {
ll n = m.size();
for (int i=0; i<31; i++) {
bool b = c[i];
vb a(31, b);
send_packet(a);
}
ll pot = 0;
vb mn(31, 0);
for (int i=0; i<31; i++) {
if (c[i]) continue;
if ((n & (1<<pot))) mn[i]=1;
pot++;
}
send_packet(mn);
ll it = m.size() / 16;
if (m.size() % 16 != 0) it++;
ll ind = 0;
for (int i=0; i<it; i++) {
vb a(31, 0);
ll j = 0;
while (ind < n && j < 31) {
if (c[j]) {
j++;
continue;
}
a[j] = m[ind];
j++;
ind++;
}
send_packet(a);
}
}
vb receive_message(vector<vb> r) {
vb c(31, 0);
for (int i=0; i<31; i++) {
vll cant(2, 0);
for (int j=0; j<31; j++) {
cant[r[i][j]]++;
}
if (cant[0] > cant[1]) c[i]=0;
else c[i] = 1;
}
ll n = 0, pot = 0;
for (int i=0; i<31; i++) {
if (c[i]) continue;
if (r[31][i]) n += (1<<pot);
pot++;
}
vb res(n, 0);
ll ind = 0;
for (int i=32; i<r.size(); i++) {
for (int j=0; j<31; j++) {
if (ind==n) break;
if (c[j]) continue;
res[ind] = r[i][j];
ind++;
}
}
return res;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |