#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);
}
idx.pb(idx[0]);
for(int i=0;i<5;i++){
vector<bool> v(31,false);
for(int j=0;j<16;j++){
v[idx[j]] = bool( ( (idx[j+1] >> i) & 1 ) );
}
send_packet(v);
}
int L = (int)M.size();
vector<bool> tmp(31,false);
for(int i=0;i<15;i++){
if(L & (1<<i)) tmp[idx[i]] = 1;
}
send_packet(tmp);
int full = L / 16;
for(int i=0;i<full;i++){
vector<bool> v(31,false);
for(int j=0;j<16;j++){
v[idx[j]] = M[i*16 + j];
}
send_packet(v);
}
if(L % 16){
vector<bool> v(31,false);
for(int j=0;j<L%16;j++){
v[idx[j]] = M[full*16 + j];
}
send_packet(v);
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
int P = (int)R.size();
vector<int> child(31,0);
for(int t=0;t<5 && t<P;t++){
for(int j=0;j<31;j++){
if(R[t][j]) child[j] |= (1<<t);
}
}
vector<int> vis(31,0);
vector<int> idx;
for(int start=0; start<31; ++start){
if(vis[start]) continue;
int cur = start;
unordered_map<int,int> pos;
int step = 0;
while(pos.find(cur) == pos.end()){
if(vis[cur]) break;
pos[cur] = step++;
cur = child[cur];
}
if(pos.find(cur) != pos.end()){
int cycle_len = step - pos[cur];
if(cycle_len == 16){
int node = cur;
for(int k=0;k<16;k++){
idx.pb(node);
node = child[node];
}
break;
}
}
for(auto &p : pos) vis[p.first]=1;
}
if(idx.empty()) return {};
int L = 0;
if(P > 5){
for(int i=0;i<15;i++){
if(R[5][idx[i]]) L += (1<<i);
}
}
int need = L;
vector<bool> M;
if(need==0) return M;
int msgPackets = (need + 15) / 16;
for(int k=0;k<msgPackets;k++){
int pi = 6 + k;
for(int j=0;j<16;j++){
int bitpos = k*16 + j;
if(bitpos >= need) break;
bool val = false;
if(pi < P) val = R[pi][ idx[j] ];
M.pb(val);
}
}
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... |