#include "message.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
void send_message(std::vector<bool> M, std::vector<bool> C) {
vector<int>idx;
for(int i=0;i<31;i++){
if(C[i]==0)idx.pb(i); //16 shirheg
}
idx.pb(idx[0]);
for(int i=0;i<5;i++){
vector<bool>v(31);
for(int j=0;j<16;j++){
v[idx[j]]= bool ((1<<i) & (idx[j+1]));
}
send_packet(v);
}
int L=M.size();
vector<bool>tmp(31);
for(int i=0;i<15;i++){
if(L & (1<<i)){
tmp[idx[i]]=1;
}
}
send_packet(tmp);
for(int i=0;i<L/16;i++){
vector<bool>v(31);
for(int j=0;j<16;j++){
v[idx[j]]=M[i*16+j];
}
send_packet(v);
}
if(L%16){
vector<bool>v(31);
for(int j=0;j<L%16;j++){
v[idx[j]]=M[L-L%16+j];
}
send_packet(v);
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
vector<int>child(31);
for(int i=0;i<5;i++){
for(int j=0;j<31;j++){
child[j]+= (1<<i) * R[i][j];
}
}
vector<int>idx;
for(int x=0;x<31;x++){
int a=x;
vector<int> pos(31, -1);
vector<int> path;
while(true){
if(a<0 || a>=31) break;
if(pos[a]!=-1){
int st=pos[a];
for(int t=st;t<(int)path.size();t++) idx.pb(path[t]);
break;
}
pos[a]=path.size();
path.pb(a);
a=child[a];
}
if(idx.size()==16) break;
idx.clear();
}
sort(idx.begin(),idx.end());
int L=0;
for(int i=0;i<15;i++){
if(R[5][idx[i]])L+=(1<<i);
}
vector<bool>M(L);
for(int i=0;i<L/16;i++){
vector<bool>v(31);
for(int j=0;j<16;j++){
M[i*16+j]=R[i+6][idx[j]];
}
}
if(L%16){
vector<bool>v(31);
for(int j=0;j<L%16;j++){
M[L-L%16+j]=R.back()[idx[j]];
}
}
return M;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |