#include "message.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ll long long int
const int N = 1e5+100;
void send_message(std::vector<bool> e, std::vector<bool> C) {
vi P, d(16);
reverse(all(e));
int nw = 0;
if(e.size() < 1009){
for(int j = 0; j < 16; ++j) e.pb(1), ++nw;
}
while(e.size() % 16 != 0){
e.pb(1);
++nw;
}
reverse(all(e));
e[nw - 1] = 0;
for(int i = 0; i < 31; ++i) if(C[i] == 0) P.pb(i);
for(int i = 0; i < 16; ++i) d[i] = (i == 15 ? P[0] + 31 - P[i]: P[i + 1] - P[i]) - 1;
// for(int x: d) cerr << x << ' ';
for(int i = 0; i < 4; ++i){
vector<bool> m(31);
for(int j = 0; j < 16; ++j){
if((1<<i)&d[j]){
m[P[j]] = 1;
}else{
m[P[j]] = 0;
}
}
send_packet(m);
}
// for(int x: e) cerr << x << ' ';
// cerr << '\n';
for(int i = 0; i < e.size(); ){
vector<bool> m(31);
for(int j = 0; j < 16; ++i, ++j){
m[P[j]] = e[i];
}
send_packet(m);
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
vi go(31);
for(int i = 0; i < 4; ++i){
for(int j = 0; j < 31; ++j){
go[j] += (1<<i)*R[i][j];
}
}
for(int j = 0; j < 31; ++j) go[j] = (j + go[j] + 1) % 31;
vi T;
vector<bool> nice(31);
for(int i = 0; i < 31; ++i){
int v = i;
int cnt = 0;
vector<bool> vis(31);
T.clear();
while(!vis[v]){
T.pb(v);
vis[v] = 1;
v = go[v];
cnt++;
}
if(cnt == 16){
for(int x: T) nice[x] = 1;
break;
}
}
vector<bool> res;
for(int i = 4; i < (int) R.size(); ++i){
for(int j = 0; j < 31; ++j){
if(nice[j]) res.pb(R[i][j]);
}
}
reverse(all(res));
while(res.back() == 1) res.pop_back();
res.pop_back();
reverse(all(res));
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... |