#include <bits/stdc++.h>
#include "message.h"
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x << ' '; print(x); cerr << endl;
#else
#define dbg(x)
#endif
void print(int x) {cerr << x;}
void print(long long x) {cerr << x;}
void print(char x) {cerr << x;}
void print(string x) {cerr << x;}
void print(double x) {cerr << x;}
template <class T> void print(vector <T> x);
template <class T> void print(set <T> x);
template <class T> void print(multiset <T> x);
template <class T, class V> void print(pair <T, V> x);
template <class T, class V> void print(map <T, V> x);
template <class T> void print(vector <T> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
template <class T> void print(set <T> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
template <class T> void print(multiset <T> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
template <class T, class V> void print(pair <T, V> x) {cerr << "{"; print(x.first); cerr << ' '; print(x.second); cerr << "}";}
template <class T, class V> void print(map <T, V> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
#define ll long long
#define pb push_back
#define ppb pop_back
#define PII pair <int, int>
#define PLL pair <ll, ll>
#define all(v) (v).begin(), (v).end()
#define OK cerr << "OK\n";
#define MP make_pair
void send_message(vector <bool> M, vector <bool> C){
int S = M.size();
vector <bool> packet(31);
vector <int> indx;
for(int i = 0; i < 17; i++){
packet.assign(31, C[i]);
packet = send_packet(packet);
if(!C[i] && indx.size() < 2) indx.pb(i);
}
int fst = indx.front(), scnd = indx[1];
for(int i = 17; i < 31; i += 2){
packet[fst] = C[i];
packet[scnd] = C[i + 1];
}
vector <int> indices;
for(int i = 0; i < 31; i++){
if(!C[i]) indices.pb(i);
}
for(int i = 0; i < 16; i++){
if(S & (1 << i)) packet[indices[i]] = 1;
else packet[indices[i]] = 0;
}
packet = send_packet(packet);
int curr_filled = 0;
for(int i = 0; i < S; i++){
if(curr_filled < 16){
packet[indices[curr_filled]] = M[i];
curr_filled++;
}
if(curr_filled == 16){
packet = send_packet(packet);
curr_filled = 0;
}
}
if(curr_filled){
packet = send_packet(packet);
}
}
vector <bool> receive_message(vector <vector <bool>> R){
vector <bool> c(31);
vector <int> indices;
for(int i = 0; i < 17; i++){
int cnt = 0;
for(int j = 0; j < 31; j++){
cnt += R[i][j];
}
c[i] = (2 * cnt > 31);
if(!c[i]) indices.pb(i);
}
int fst = indices.front(), scnd = indices[1];
for(int i = 17; i < 24; i++){
if(!R[i][fst]) indices.pb(i);
if(!R[i][scnd]) indices.pb(i + 1);
}
int s = 0;
for(int i = 0; i < 16; i++){
s += R[24][indices[i]] * (1 << i);
}
vector <bool> answ;
int curr_packet = 25, curr_pos = 0;
while(answ.size() != s){
answ.pb(R[curr_packet][indices[curr_pos]]);
curr_pos++;
if(curr_pos == 16){
curr_pos = 0;
curr_packet++;
}
}
return answ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |