#include "message.h"
#include <bits/stdc++.h>
using namespace std;
void send_message(vector<bool> M, vector<bool> C)
{
vector<int> idx;
for(int i = 0; i < (int)C.size(); i++)
if(C[i] == 0)
idx.push_back(i);
vector<int> idx2;
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 5; j++)
send_packet(vector<bool>(31, ((idx[i] >> j) & 1)));
idx2.push_back(idx[i]);
}
for(int i = 5; i < 10; i++)
{
vector<bool> b;
for(int j = 0; j < 5; j++)
b.push_back((idx[i] >> j) & 1);
vector<bool> a(31, 0);
for(int j = 0; j < 5; j++)
a[idx2[j]] = b[j];
idx2.push_back(idx[i]);
send_packet(a);
}
for(int i = 10; i < 16; i += 2)
{
vector<bool> b, c;
for(int j = 0; j < 5; j++)
{
b.push_back((idx[i] >> j) & 1);
c.push_back((idx[i + 1] >> j) & 1);
}
vector<bool> a(31, 0);
for(int j = 0; j < 5; j++)
{
a[idx2[j]] = b[j];
a[idx2[j + 5]] = c[j];
}
idx2.push_back(idx[i]);
idx2.push_back(idx[i + 1]);
send_packet(a);
}
{
int sz = (int)M.size();
vector<bool> b;
for(int j = 0; j < 10; j++)
b.push_back((sz >> j) & 1);
vector<bool> a(31, 0);
for(int j = 0; j < 10; j++)
a[idx2[j]] = b[j];
send_packet(a);
}
int curr = 0;
vector<bool> a(31, 0);
for(int i = 0; i < (int)M.size(); i++)
{
a[idx[curr++]] = M[i];
if(curr == 16)
{
send_packet(a);
a.assign(31, 0);
curr = 0;
}
}
if(curr)
send_packet(a);
}
vector<bool> receive_message(vector<vector<bool>> R)
{
vector<bool> M(31, 1);
int n = (int)R.size();
vector<int> b;
for(int i = 0; i < 5; i++)
{
int idx = 0;
for(int j = 0; j < 5; j++)
{
int k = i * 5 + j;
int cnt0 = 0;
for(auto l: R[k])
cnt0 += !l;
if(cnt0 < 16)
idx |= (1 << j);
}
M[idx] = 0;
b.push_back(idx);
}
for(int i = 25; i < 30; i++)
{
int idx = 0;
for(int j = 0; j < 5; j++)
{
if(R[i][b[j]] == 1)
idx |= (1 << j);
}
M[idx] = 0;
b.push_back(idx);
}
for(int i = 30; i < 33; i++)
{
int idx1 = 0, idx2 = 0;
for(int j = 0; j < 5; j++)
{
if(R[i][b[j]] == 1)
idx1 |= (1 << j);
if(R[i][b[j + 5]] == 1)
idx2 |= (1 << j);
}
M[idx1] = M[idx2] = 0;
b.push_back(idx1);
b.push_back(idx2);
}
int sz = 0;
for(int i = 0; i < 10; i++)
if(R[33][b[i]] == 1)
sz |= (1 << i);
vector<bool> res;
int x = 0;
for(int i = 34; i < n; i++)
{
for(int j = 0; j < 16; j++)
{
if(R[i][b[j]] == 0)
res.push_back(0);
else
res.push_back(1);
x++;
if(x == sz)
break;
}
}
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... |