#include <bits/stdc++.h>
using namespace std;
// #define DEBUG
#ifndef DEBUG
#include "communication.h"
#endif
random_device rd;
mt19937 rng(rd());
#ifdef DEBUG
queue<int> signals;
int receive() {
int now = signals.front();
signals.pop();
return now;
}
int send(int i) {
int now = rng() % 2;
signals.push(i);
// cout << i << " = " << (i ^ now) << endl;
return (i ^ now);
}
#endif
void encode(int N, int X) {
vector<int> bits;
for (int i = 0; i < 2; ++i) {
bits.push_back((X >> i & 1));
}
for (int i = 0; i < 250 / 2; ++i) {
for (int j = 0; j < 2; ++j) {
send(bits[j]);
}
}
}
std::pair<int, int> decode(int N) {
vector<int> cnt(4);
for (int i = 0; i < 250 / 2; ++i) {
int now = 0;
for (int j = 0; j < 2; ++j) {
if (receive()) {
now += (1 << j);
}
}
cnt[now]++;
}
pair<int, int> res = {0, 0};
for (int i = 1; i <= 3; ++i) {
if (cnt[res.first] < cnt[i]) {
swap(res.first, res.second);
res.first = i;
} else if (cnt[res.second] < cnt[i]) {
res.second = i;
}
}
return res;
}
#ifdef DEBUG
int main() {
int N = 3, X = 2;
// cout << now.first << " " << now.second << endl;
for (int i = 0; i < 1000; ++i) {
X = rng() % N + 1;
encode(N, X);
auto now = decode(N);
if (now.first != X && now.second != X) {
cout << "WA!\n";
return 0;
}
}
cout << "AC!\n";
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |