#include <bits/stdc++.h>
#include "message.h"
using namespace std;
void send_message(vector<bool> M, vector<bool> C){
vector<int> not_cont;
for (int i=0; i<31; i++){
vector<bool> bit_message;
if (C[i] == 0){
for (int j=0; j<31; j++) bit_message.push_back(0);
not_cont.push_back(i);
}
else{
for (int j=0; j<31; j++) bit_message.push_back(1);
}
send_packet(bit_message);
}
int msg_len = M.size();
vector<bool> pad_message;
while (pad_message.size()+1+msg_len < 1025) pad_message.push_back(0);
pad_message.push_back(1);
for (auto it : M) pad_message.push_back(it);
// for (auto it : pad_message) cout << it << "";
// cout << "\n";
int cnt = 0;
for (int i=0; i<65; i++){
vector<bool> ans(31);
for (int idx: not_cont){
ans[idx] = pad_message[cnt];
cnt++;
if (cnt > 1024) break;
}
// cout << cnt << " ";
// for (auto it : ans) cout << it << "";
// cout << "\n";
send_packet(ans);
}
}
vector<bool> receive_message(vector<vector<bool>> R){
// cout << R.size() << "\n";
vector<bool> C(31); //to reflect the same version as C in send_message
for (int i=0; i<31; i++){
int zro = 0, one = 0;
for (auto it : R[i]){
if (it == 0) zro++;
else one++;
}
if (zro > one) C[i] = 0;
else C[i] = 1;
}
// for (auto it : C) cerr << it << " ";
// cerr << "\n";
bool seen = false;
int check_cnt = 0;
vector<bool> ans;
for (int i=31; i<96; i++){
for (int j=0; j<31; j++){
if (C[j] == 1) continue;
check_cnt++;
if (check_cnt > 1025) break;
if (R[i][j] == 1 && !seen){
seen = true;
continue;
}
if (seen) ans.push_back(R[i][j]);
}
if (check_cnt > 1025) break;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |