#include "message.h"
#include "bits/stdc++.h"
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds; // order_of_key() skolko menshe, find_by_order() a[x]
// template<typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using ll = long long;
using ld = long double;
#define int ll
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
int binmul(int a, int b, int c) { int res = 0; while(b) { if(b & 1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
int binpow(int a, int b, int c) { int res = 1; while(b) { if(b & 1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const int mod = 1e9+7, N = 3e5+5;
// vector<vector<bool>> g;
// void send_packet(vector<bool> s) {
// g.pb(s);
// }
void send_message(vector<bool> M, vector<bool> C) {
bool ok = 0;
int pos = -1, cnt0 = 0, cnt1 = 0, k = 0;
vector<bool> bad(31);
for(int i = 0; i < sz(C) && cnt0 < 16 && cnt1 < 15; i++) {
if(bad[i]) {
cnt1++;
continue;
}
if(!C[i]) cnt0++;
if(C[i]) cnt1++;
if(!ok) {
vector<bool> s(31, C[i]);
s = send_packet(s);
for(int j = 0; j < 31; j++) {
if(s[j] != C[i]) bad[j] = 1;
}
}
else {
vector<bool> s(31);
s[pos] = C[i];
for(int j = 0; j <= i; j++) {
if(j == pos) continue;
if(C[j] || k == sz(M)) continue;
s[j] = M[k++];
}
s = send_packet(s);
for(int j = i+1; j < 31; j++) {
if(s[j]) bad[j] = 1;
}
}
if(!C[i]) {
if(pos == -1) pos = i;
ok = 1;
}
}
vector<bool> s(31, 0);
for(int i = 0, j = 0; i < sz(C); i++) {
if(C[i]) continue;
if(sz(M)&(1<<j)) s[i] = 1;
j++;
}
send_packet(s);
int i = k;
while(i < sz(M)) {
vector<bool> s(31);
for(int j = 0; j < sz(C) && i < sz(M); j++) {
if(C[j]) continue;
s[j] = M[i];
i++;
}
send_packet(s);
}
}
vector<bool> receive_message(vector<vector<bool>> R) {
// vector<vector<bool>> R = g;
// for(auto cur: R) {
// for(int i = 0; i < sz(cur); i++) cout << cur[i] << " ";
// cout << "\n";
// }
vector<bool> C, ans, bad(31);
bool ok = 0;
int t = 0, cnt0 = 0, cnt1 = 0, pos = -1;
while(cnt0 < 16 && cnt1 < 15) {
if(bad[sz(C)]) {
cnt1++;
C.pb(1);
continue;
}
if(!ok) {
int cnt = 0;
for(int j = 0; j < 31; j++) {
if(R[t][j]) cnt++;
}
if(cnt >= 16) {
cnt1++;
C.pb(1);
}
else {
if(pos == -1) pos = sz(C);
C.pb(0);
cnt0++;
ok = 1;
}
for(int j = 0; j < 31; j++) {
if(R[t][j] != C.back()) bad[j] = 1;
}
}
else {
C.pb(R[t][pos]);
if(C.back()) cnt1++;
else cnt0++;
for(int j = 0; j < sz(C); j++) {
if(C[j] || j == pos) continue;
ans.pb(R[t][j]);
}
for(int j = sz(C); j < 31; j++) {
if(R[t][j]) bad[j] = 1;
}
}
t++;
}
while(sz(C) < 31) {
if(cnt0 < 16) C.pb(0);
else C.pb(1);
}
int len = 0;
for(int i = 0, j = 0; i < sz(C); i++) {
if(C[i]) continue;
if(R[t][i]) len += (1<<j);
j++;
}
for(int i = t+1; i < sz(R); i++) {
for(int j = 0; j < 31 && sz(ans) < len; j++) {
if(C[j]) continue;
ans.pb(R[i][j]);
}
}
while(sz(ans) > len) ans.pop_back();
return ans;
}
//
// signed main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// vector<bool> C;
// for(int i = 0; i < 31; i++) {
// int x;
// cin >> x;
// C.pb(x);
// }
// send_message({0, 1, 1, 0}, C);
// vector<bool> ans = receive_message();
// for(int i = 0; i < sz(ans); i++) cout << ans[i] << " ";
// cout << "\n";
// return 0;
// }
Compilation message (stderr)
message.cpp: In function 'void freopen(std::string)':
message.cpp:24:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
message.cpp:24:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |