#include <bits/stdc++.h>
#include "message.h"
#define pb push_back
using namespace std;
void send_message(vector<bool> M, vector<bool> C){
for(int i=0; i<30; i++){
if(C[i]==0) send_packet(vector<bool> (31,0));
else send_packet(vector<bool> (31,1));
}
vector<int> p(16);
int pp=0;
for(int i=0; i<31; i++){
if(C[i]==0){
p[pp]=i;
pp++;
}
}
int s=M.size();
int atl=s%16;
atl--;
if(atl==-1) atl=15;
vector<bool> v(31,0);
v[p[atl]]=1;
send_packet(v);
pp=0;
while(pp<s){
vector<bool> A(31,0);
for(int i=0; i<16; i++){
if(pp>=s) break;;
A[p[i]]=M[pp];
pp++;
}
send_packet(A);
}
return;
}
vector<bool> receive_message(vector<vector<bool>> R) {
vector<bool> C(31,0);
int pa=0,ne=0;
for(int i=0; i<30; i++){
int v=0,n=0;
for(int j=0; j<31; j++){
if(R[i][j]==1) v++;
else n++;
}
if(v>n){
C[i]=1;
ne++;
}else{
C[i]=0;
pa++;
}
}
if(pa==15) C[30]=0;
else C[30]=1;
int last;
for(int i=0; i<31; i++){
if(R[30][i]==1 && C[i]==0){
last=i;
break;
}
}
vector<bool> B;
for(int i=31; i<R.size()-1; i++){
for(int j=0; j<31; j++){
if(C[j]==0){
B.pb(R[i][j]);
}
}
}
for(int i=0; i<=last; i++){
if(C[i]==0){
B.pb(R[R.size()-1][i]);
}
}
return B;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |