#include <bits/stdc++.h>
#include "message.h"
using namespace std;
/*vector<vector<bool>> B;
vector<bool> send_packet(vector<bool> A)
{
B.push_back(A);
return A;
}*/
void send_message(vector<bool> M, vector<bool> C)
{
vector<int> dist(31);
int last = 0, first = -1;
for (int i = 0; i < 31; i++)
{
if (C[i] == 0)
{
if (first == -1)
first = i;
dist[last] = i - last;
last = i;
}
}
dist[last] = 31 + first - last;
int buff = 0;
vector<bool> A(31);
for (int i = 0; i < 66; i++)
{
A.assign(31, 0);
for (int j = 0; j < 31; j++)
{
if (C[j] == 0)
{
if (dist[j] == 0)
A[j] = 1;
if (dist[j] >= 0)
dist[j]--;
else if (buff < M.size())
A[j] = M[buff++];
else if (buff == M.size())
{
A[j] = 1;
buff++;
}
}
}
vector<bool> temp = send_packet(A);
}
}
vector<bool> receive_message(vector<vector<bool>> R)
{
vector<int> dist(31);
for (int i = 0; i < 31; i++)
{
for (int j = 0; j < 66; j++)
{
if (R[j][i])
break;
dist[i]++;
}
}
vector<int> C(31), occ(31);
int good = -1;
for (int i = 0; i < 31; i++)
{
if (good != -1)
break;
if (occ[i])
continue;
int x = i, len = 1;
while (occ[x] == 0)
{
occ[x] = len++;
x = (x + dist[x]) % 31;
}
if (len - occ[x] == 16)
good = x;
}
for (int i = 0; i < 16; i++)
{
C[good] = 1;
good = (good + dist[good]) % 31;
}
vector<bool> ans;
for (int i = 0; i < 66; i++)
{
for (int j = 0; j < 31; j++)
{
if (C[j] == 0)
continue;
if (dist[j] >= i)
continue;
ans.push_back(R[i][j]);
}
}
while (ans.back() == 0)
ans.pop_back();
ans.pop_back();
return ans;
}
/*int main()
{
vector<bool> C(31);
int S;
cin >> S;
vector<bool> M(S);
for (int i = 0; i < S; i++)
{
int x;
cin >> x;
M[i] = x;
}
for (int i = 0; i < 31; i++)
{
int x;
cin >> x;
C[i] = x;
}
send_message(M, C);
vector<bool> temp = receive_message(B);
for (int i = 0; i < temp.size(); i++)
cout << temp[i];
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |