#include <bits/stdc++.h>
#include "message.h"
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int M=31;
void send_message(std::vector<bool> A, std::vector<bool> C){
vector<int>idx;int trenutak[M+5]={0};
for(int i=0;i<M;i++) if(!C[i]) idx.pb(i);
for(int i=1;i<idx.size();i++) trenutak[idx[i-1]]=idx[i]-idx[i-1];
trenutak[idx.back()]=M-(idx.back()-idx[0]);
reverse(A.begin(),A.end());
A.pb(1);while(A.size()<1025) A.pb(0);
reverse(A.begin(),A.end());
for(int i=0,k=0;i<A.size();k++){
vector<bool>temp(M,0);
for(int j=0;j<M&&i<A.size();j++){
if(C[j]==1) continue;
if(trenutak[j]==k+1) temp[j]=1;
else if(k+1>trenutak[j]) temp[j]=A[i++];
}
send_packet(temp);
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R){
vector<bool>res,C(M,1);
int sledeci[M+10];
for(int j=0;j<M;j++){
sledeci[j]=j+1;
for(int i=0;i<R.size();i++) if(R[i][j]==1){sledeci[j]+=i;break;}
sledeci[j]%=M;
}
for(int i=0;i<M;i++){
int u=i,ct=0;
bool was[M+10]={false};
while(!was[u]){
was[u]=true;
u=sledeci[u];
ct++;
}
if(ct==16) C[i]=0;
}
bool bul[M+10]={false};
for(int I=0;I<R.size();I++){
vector<bool>temp=R[I];
for(int j=0;j<M&&res.size()<1025;j++){
if(C[j]==1) continue;
if(bul[j]) res.pb(temp[j]);
if(temp[j]) bul[j]=true;
}
}
reverse(res.begin(),res.end());
while(!res.back()) res.pop_back();res.pop_back();
reverse(res.begin(),res.end());
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |