#include "message.h"
#include <bits/stdc++.h>
using namespace std;
const int LIMIT = 66;
void send_message(std::vector<bool> M, std::vector<bool> C) {
std::vector<bool> A(31, 0);
std::vector<bool> send[31];
std::vector<int> zeros;
for (int i = 0; i < 31; ++i) {
if (C[i] == 0) {
zeros.push_back(i);
}
}
zeros.push_back(zeros[0] + 31);
int curs = 0;
for (int i = 0, j = 1; i < 31; ++i) {
if (C[i] == 0) {
int dist = zeros[j] - i;
for (int d = 1; d < dist; ++d) {
send[i].push_back(1);
curs++;
}
send[i].push_back(0);
curs++;
++j;
}
}
int f = 1025 - M.size();
int cur = -f;
for (int i = 0; i < 31; ++i) {
if (C[i] == 0) {
while (cur < -1 && send[i].size() < LIMIT) {
send[i].push_back(0);
cur++;
}
if (cur == -1 && send[i].size() < LIMIT) {
send[i].push_back(1);
cur++;
}
while (cur < (int)M.size() && send[i].size() < LIMIT) {
send[i].push_back(M[cur++]);
}
} else {
while (send[i].size() < LIMIT) {
send[i].push_back(0);
}
}
}
for (int i = 0; i < LIMIT; ++i) {
for (int j = 0; j < 31; ++j) {
A[j] = send[j][i];
}
send_packet(A);
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
vector<bool> res;
vector<int> nxt(31, -1);
vector<bool> C[31];
int N = (int)R.size();
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 31; ++j) {
// cout << R[i][j] << " ";
C[j].push_back(R[i][j]);
}
// cout << endl;
}
// cout << endl;
for (int i = 0; i < 31; ++i) {
auto& v = C[i];
// for (auto u : v) {
// cout << u << " ";
// }
// cout << endl;
if (v[0] == 0) {
nxt[i] = (i + 1) % 31;
v.erase(v.begin());
} else {
int dist = 0;
while (v.size() && v[0] == 1) {
dist++;
v.erase(v.begin());
}
// cout << i << " = " << dist << "\n";
dist++;
nxt[i] = (i + dist) % 31;
v.erase(v.begin());
}
}
int start = -1;
for (int i = 0; i < 31; ++i) {
cout << nxt[i] << " ";
}
cout << endl;
for (int i = 0; start == -1 && i < 31; ++i) {
if (nxt[i] == -1) continue;
int j = i;
int d = 0;
while (d < 16 && j >= i) {
d++;
j = nxt[j];
if (j == i) break;
}
if (d == 16 && j == i) {
start = i;
}
// cout << i << " -> " << j << endl;
}
// assert(start != -1);
bool good[31];
for (int i = 0; i < 31; ++i) good[i] = false;
{
int ni = start;
good[ni] = true;
ni = nxt[ni];
while (ni != start) {
good[ni] = true;
ni = nxt[ni];
}
}
for (int i = 0; i < 31; ++i) {
cout << good[i] << " ";
}
cout << endl;
bool can = false;
for (int i = 0; i < 31; ++i) {
if (good[i]) {
auto& v = C[i];
int j = (nxt[i] - i + 31) % 31;
// for (auto u : v) {
// cout << u << " ";
// }
// cout << "\n";
for (auto u : v) {
j++;
if (!can && u == 1) {
can = true;
cout << "STARTING AT " << i << " " << j - 1 << "\n";
continue;
}
if (can) {
res.push_back(u);
cout << "NOW AT " << i << " " << j - 1 << "\n";
}
}
}
}
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... |