#include "communication.h"
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define chmax(x, v) x = max(x, v)
#define chmin(x, v) x = min(x, v)
#define pb push_back
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
vector<int> bits;
bool modif = false;
int send(int bit){
bool tom = rand()%2;
if (modif) tom = false;
modif = tom;
bits.pb(bit^tom);
return bit^tom;
}
int receive(){
int to = bits.back();
bits.pop_back();
return to;
}
void encode(int N, int X){
if (X == 1){
for (int i = 0; i < 6; ++i)
int ans = send(0);
}
else if (X == 2){
for (int i = 0; i < 6; ++i)
int ans = send(1);
}
else {
for (int i = 0; i < 6; ++i)
int ans = send(i%3 == 0);
}
}
pii decode(int N){
vector<int> vals;
for (int i = 0; i < 6; ++i)
vals.pb(receive());
set<int> possibles;
for (int mask = 0; mask < (1 << 6); ++mask){
bool valid = true;
vector<int> inds;
for (int i = 0; i < 6; ++i){
if ((mask&(1 << i)) > 0)
inds.pb(i);
}
for (int i = 0; i < sz(inds) - 1; ++i)
valid &= (inds[i] != inds[i + 1] - 1);
if (!valid) continue;
/* cout << "mask " << endl;
for (int i : inds)
cout << i << " ";
cout << endl;*/
vector<int> change = vals;
for (int ind : inds)
change[ind] ^= 1;
bool un = true, deux = true, trois = true;
for (int i = 0; i < 6; ++i){
un &= change[i] == 0;
deux &= change[i] == 1;
trois &= !(change[i]^(i%3 == 0));
}
/*
for (int i : change)
cout << i;
cout << endl;
for (int i = 0; i < 6; ++i)
cout << (change[i]^(i%3 == 0));
cout << endl;
*/
if (un)
possibles.insert(1);
if (deux)
possibles.insert(2);
if (trois)
possibles.insert(3);
}
// cout << sz(possibles) << endl;
vector<int> v;
for (int a : possibles)
v.pb(a);
if (sz(v) == 2)
return {v[0], v[1]};
else if (sz(v) == 1)
return {v[0], 1};
else
return {-1, -1};
}
Compilation message
communication.cpp: In function 'void encode(int, int)':
communication.cpp:32:23: warning: unused variable 'ans' [-Wunused-variable]
32 | int ans = send(0);
| ^~~
communication.cpp:36:23: warning: unused variable 'ans' [-Wunused-variable]
36 | int ans = send(1);
| ^~~
communication.cpp:40:23: warning: unused variable 'ans' [-Wunused-variable]
40 | int ans = send(i%3 == 0);
| ^~~
/usr/bin/ld: /tmp/ccBHoxDA.o: in function `send(int)':
interface.cpp:(.text+0x70): multiple definition of `send(int)'; /tmp/ccc1LYny.o:communication.cpp:(.text+0x720): first defined here
/usr/bin/ld: /tmp/ccBHoxDA.o: in function `receive()':
interface.cpp:(.text+0x100): multiple definition of `receive()'; /tmp/ccc1LYny.o:communication.cpp:(.text+0x1d0): first defined here
collect2: error: ld returned 1 exit status