#include <vector>
#include <map>
#include <algorithm>
#include "message.h"
void send_message(std::vector<bool> M, std::vector<bool> C) {
const int W = 31; // fixed width as in the Python code
const int S = static_cast<int>(M.size());
// (Assume C has at least 31 elements; mirror the Python behavior.)
for (int i = 0; i < S; ++i) {
std::vector<bool> A(W, false);
for (int j = 0; j < W; ++j) {
if (!C[j]) {
A[j] = M[i];
} else {
// (i % 2) XOR M[i]
A[j] = static_cast<bool>((i % 2) ^ static_cast<int>(M[i]));
}
}
(void)send_packet(A); // ignore return, Python didn't use it
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
const int W = 31; // fixed width as in the Python code
const int n = static_cast<int>(R.size());
// Count occurrences of each column sequence
std::map<std::vector<bool>, int> count;
for (int j = 0; j < W; ++j) {
std::vector<bool> seq;
seq.reserve(n);
for (int i = 0; i < n; ++i) {
// Assume each row has at least 31 entries (like the Python version)
seq.push_back(R[i][j]);
}
++count[seq];
}
// Return any sequence that appears at least 16 times
for (const auto& kv : count) {
if (kv.second >= 16) {
return kv.first;
}
}
// Otherwise return the first (arbitrary in Python; lexicographically first in map)
if (!count.empty()) {
return count.begin()->first;
}
return {};
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |