Submission #1198822

#TimeUsernameProblemLanguageResultExecution timeMemory
1198822viduxMessage (IOI24_message)C++17
17.48 / 100
575 ms856 KiB
#include <bits/stdc++.h>
using namespace std;

//#define LOCAL

#ifndef LOCAL
#include "message.h"
#endif

#define FOR(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n, m) for (int i = n; i <= m; ++i)
#define REPR(i, n, m) for (int i = n; i >= m; --i)
#define FORR(x, a) for (auto& x : a)
#define FORR2(x, y, a) for (auto& [x, y] : a)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SZ(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;

const int INF = 1e9;
const ll LLINF = 1e18;
const int N = 31;

#ifdef LOCAL
vb LOCAL_C;
vvb R;
std::vector<bool> send_packet(std::vector<bool> A) {
	vb ret(N);
	FOR(i, N) 
		if (LOCAL_C[i]) ret[i] = rand() % 2;
		else ret[i] = A[i];
	//cout << "sending: "; FOR(i, N) cout << ret[i] << " "; cout << endl;
	R.push_back(ret);
	//if (SZ(R) == 31) cout << endl;
	return ret;
}
#endif

void send_message(std::vector<bool> M, std::vector<bool> C) {
	int sent = 0;
#ifdef LOCAL
	LOCAL_C = C;
#endif
	FOR(i, N) {
		vb a(N);
		FOR(j, N) a[j] = C[i];
		send_packet(a);
		sent++;
	}
	vi idxs;
	FOR(i, N) if (!C[i]) idxs.push_back(i);
	vb curM(31);
	int im = 0, icm = 0;
	while (im < SZ(M)) {
		curM[idxs[icm]] = M[im++];
		icm = (icm + 1) % 16;
		if (icm == 0) send_packet(curM), sent++;
	}
	if (icm != 0) send_packet(curM), sent++;
	while (sent < 99) send_packet(curM), sent++;
	int sz = SZ(M);
	curM = vb(N);
	FOR(i, 11) curM[idxs[i]] = sz & (1 << i);
	send_packet(curM);
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
	vb C(N);
	FOR(i, N) {
		int cnt[2] = {0};
		FOR(j, N) cnt[R[i][j]]++;
		if (cnt[0] >= 16) C[i] = 0;
		else C[i] = 1;
	}
	vi idxs;
	FOR(i, N) if (!C[i]) idxs.push_back(i);
	int sz = 0;
	FOR(i, 11) sz |= (1 << i) * R.back()[idxs[i]];
	//cout << "sz: " << sz << endl;
	vb ans;
	REP(i, N, 99) {
		vb seg(16);
		FOR(j, 16) seg[j] = R[i][idxs[j]];
		//cout << "read: "; FOR(j, 16) cout << seg[j] << " "; cout << endl;
		FOR(j, 16) {
			ans.push_back(seg[j]);
			if (SZ(ans) == sz) break;
		}
		if (SZ(ans) == sz) break;
	}

#ifdef LOCAL
	//cout << "sz: " << sz << endl;
	//cout << "ans: ";
	//FOR(i, SZ(ans)) cout << ans[i] << " "; cout << endl;
#endif
	return ans;
}

#ifdef LOCAL
int main() {
	int t; cin >> t;
	while (t--) {
		R.clear();
		int n; cin >> n;
		vb a(n);
		FOR(i, n) { int x; cin >> x; a[i] = x; }
		vb c(N);
		FOR(i, N) { int x; cin >> x; c[i] = x; }
		send_message(a, c);
		vb ans = receive_message(R);
		FOR(i, SZ(ans)) cout << ans[i] << " "; cout << endl;
	}
    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...