#ifndef hwe
#include "message.h"
#endif
#include <bits/stdc++.h>
using namespace std;
#define popcount(n) (__builtin_popcountll((n)))
#define clz(n) (__builtin_clzll((n)))
#define ctz(n) (__builtin_ctzll((n)))
#define lg(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))
#define Int __int128
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;
template <class T1, class T2>
bool maximize(T1 &x, T2 y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T>
void remove_duplicate(vector<T> &ve) {
sort (ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T> T random(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
template <class T> T random(T r) {
return rng() % r;
}
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;
#ifdef hwe
vector<bool> M, C;
vector<vector<bool>> R;
vector<bool> send_packet(vector<bool> A) {
assert(A.size() == 31);
for (int i = 0; i < 31; ++i) if (C[i] == 1) {
A[i] = random(2);
}
R.emplace_back(A);
return A;
}
#endif
void send_message(vector<bool> M, vector<bool> C) {
vector<int> pos; pos.reserve(16);
for (int i = 0; i < 31; ++i) if (!C[i]) {
pos.emplace_back(i);
}
assert(pos.size() == 16);
// send one bit of C
int oneBit = pos[0];
for (int i = 0; i < 5; ++i) {
send_packet(vector<bool>(31, BIT(oneBit, i)));
}
int sz = M.size(), bit = 0, bitM = 0; vector<bool> packet(31);
for (int i = 1; i < 16; ++i) {
for (int j = 0; j < 5; ++j) {
packet[oneBit] = BIT(pos[i], j);
for (auto p : pos) if (p != oneBit && bitM < sz) {
if (i == 1 && j == 0) packet[p] = BIT(sz, bit++);
else packet[p] = M[bitM++];
}
send_packet(packet);
}
}
}
vector<bool> receive_message(vector<vector<bool>> R) {
// receive one bit of C
int oneBit = 0;
for (int i = 0; i < 5; ++i) {
vector<bool> packet = R[i];
int zeros = 0, ones = 0;
for (auto x : packet) zeros += !x, ones += x;
if (ones > zeros) oneBit = ON(oneBit, i);
}
vector<int> pos = {oneBit};
for (int i = 1; i < 16; ++i) {
int p = 0;
for (int j = 0; j < 5; ++j) {
vector<bool> &packet = R[5 * i + j];
if (packet[oneBit]) p = ON(p, j);
}
pos.emplace_back(p);
}
int sz = 0, bit = 0; vector<bool> M;
for (int i = 1; i < 16; ++i) {
for (int j = 0; j < 5; ++j) {
vector<bool> &packet = R[5 * i + j];
for (auto p : pos) if (p != oneBit && (sz == 0 || M.size() < sz)) {
if (i == 1 && j == 0) sz |= int(packet[p]) * MASK(bit++);
else M.emplace_back(packet[p]);
}
}
}
// cerr << "sz = " << sz << '\n';
return M;
}
#ifdef hwe
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
M.assign(3, 0), C.assign(31, 0), R.clear();
for (int i = 0; i < M.size(); ++i) {
M[i] = random(2);
}
vector<int> index(31); iota(index.begin(), index.end(), 0);
shuffle(index.begin(), index.end(), rng);
for (int i = 0; i < 15; ++i) C[index[i]] = 1;
for (auto x : M) cerr << x;
cerr << '\n';
for (auto x : C) cerr << x;
cerr << '\n';
// for (int i = 0; i < 31; ++i) {
// int x; cin >> x;
// M[i] = x;
// }
// for (int i = 0; i < 31; ++i) {
// int x; cin >> x;
// C[i] = x;
// }
send_message(M, C);
cerr << "Packets used: " << R.size() << '\n';
vector<bool> ans = receive_message(R);
for (auto x : ans) cerr << x;
cerr << '\n';
if (ans == M) cerr << "Accepted\n";
else cerr << "Wrong Answer\n";
cerr << '\n'; return 0;
}
#endif
Compilation message
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:134:63: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
134 | for (auto p : pos) if (p != oneBit && (sz == 0 || M.size() < sz)) {
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
656 KB |
Used 80 days |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3000 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
656 KB |
Used 80 days |
2 |
Execution timed out |
3000 ms |
328 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |