#include "message.h"
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
#define rep(i, k, n) for (int i =k; i < n; i++)
using ll = long long;
using pii = pair<int, int>;
void send_message(std::vector<bool> M, std::vector<bool> C) {
rep(i, 0, 31) {
v<bool> A(31, C[i]);
send_packet(A);
}
//for (auto x : M) cout << x << " ";
//cout << endl;
v<bool> lg(31, false);
int k = M.size();
//cout << k << endl;
rep(i, 0, 31) {
if (C[i] == 1) continue;
//cout << (k&1) << " " << k << endl;
if (k&1) lg[i] = true;
k /= 2;
}
send_packet(lg);
int l = 0;
rep(i, 0, (int)M.size()) {
if (l == (int)M.size()) break;
v<bool> A(31, false);
rep(j, 0, 31) {
if (l == (int)M.size()) break;
if (C[j]) continue;
A[j] = M[l];
l++;
}
send_packet(A);
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
v<bool> C(31);
//cout << R.size() << endl;
rep(i, 0, 31) {
int cnt = 0;
rep(j, 0, 31) {
if (R[i][j] == false) cnt++;
}
if (cnt > 31-cnt) C[i] = false;
else C[i] = true;
}
v<bool> aux = R[31];
int n = 0;
int b = 0;
//cout << endl;
rep(i, 0, 31) {
if (C[i]) continue;
if (aux[i]) n += (1 << b);
b++;
}
//cout << n << endl;
v<bool> message(n);
int l = 0;
rep(i, 32, (int)R.size()) {
if (l == n) break;
rep(j, 0, 31) {
//cout << R[i][j] << " ";
if (l == n) break;
if (C[j]) continue;
message[l] = R[i][j];
l++;
}
//cout << endl;
}
return message;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |