# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121012 | woohyun_jng | Message (IOI24_message) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include "message.h"
#include <bits/stdc++.h>
using namespace std;
void send_message(vector<bool> M, vector<bool> C) {
vector<bool> A(31, 0);
vector<int> B;
for (int i = 0; i < 31; i++) {
fill(A.begin(), A.end(), !C[i]);
send_packet(A);
if (!C[i])
B.push_back(i);
if (B.size() == 5) {
for (int j = i + 1; j < 31; j++) {
if (!C[j]) {
B.push_back(j);
continue;
}
for (int k = 0; k < 5; k++)
A[B[k]] = j & (1 << k);
send_packet(A);
}
break;
}
}
int S = M.size();
for (int j = 0; j < 10; j++)
A[B[j]] = S & (1 << j);
send_packet(A);
for (int i = 0; i < (S + 15) / 16; i++) {
for (int j = 0; j < 16 && 16 * i + j < S; j++)
A[B[j]] = M[16 * i + j];
send_packet(A);
}
}
vector<bool> receive_message(vector<vector<bool>> R) {
vector<bool> res, C(31, 1);
vector<int> cor, nt;
int cnt = 0, val, S = 0;
for (int i = 0; i < R.size(); i++) {
cnt = 0;
for (bool j : R[i])
cnt += j;
if (cnt >= 16)
cor.push_back(i);
else
nt.push_back(i);
if (cor.size() == 5) {
for (int j = i + 1; j < 20; j++) {
val = 0;
for (int k = 4; k >= 0; k--)
val = (val << 1) | R[j][cor[k]];
nt.push_back(val);
}
break;
}
}
for (int i : nt)
C[i] = 0;
cor.clear();
for (int i = 0; i < 31; i++)
if (C[i])
cor.push_back(i);
for (int i = 9; i >= 0; i--)
S = S << 1 | R[20][cor[i]];
for (int i = 21; i < R.size(); i++)
for (int j = 0; j < 16; j++)
if ((i - 21) * 16 + j < S)
res.push_back(R[i][cor[j]]);
return res;
}
namespace {
const int PACKET_SIZE = 31;
const int CALLS_CNT_LIMIT = 100;
int calls_cnt;
std::vector<bool> C(PACKET_SIZE);
std::vector<std::vector<bool>> R;
void quit(const char *message) {
printf("%s\n", message);
exit(0);
}
void run_scenario() {
R.clear();
calls_cnt = 0;
int S;
assert(1 == scanf("%d", &S));
std::vector<bool> M(S);
for (int i = 0; i < S; i++) {
int bit;
assert(1 == scanf("%d", &bit));
assert((bit == 0) || (bit == 1));
M[i] = bit;
}
for (int i = 0; i < PACKET_SIZE; i++) {
int bit;
assert(1 == scanf("%d", &bit));
assert((bit == 0) || (bit == 1));
C[i] = bit;
}
send_message(M, C);
std::vector<bool> D = receive_message(R);
int K = (int)R.size();
int L = (int)D.size();
printf("%d %d\n", K, L);
for (int i = 0; i < L; i++)
printf("%s%d", (i == 0 ? "" : " "), (D[i] ? 1 : 0));
printf("\n");
}
std::vector<bool> taint(const std::vector<bool> &A) {
std::vector<bool> B = A;
bool bit = 0;
for (int i = 0; i < PACKET_SIZE; i++)
if (C[i] == 1) {
B[i] = bit;
bit = !bit;
}
return B;
}
} // namespace
std::vector<bool> send_packet(std::vector<bool> A) {
calls_cnt++;
if (calls_cnt > CALLS_CNT_LIMIT)
quit("Too many calls");
if ((int)A.size() != PACKET_SIZE)
quit("Invalid argument");
std::vector<bool> B = taint(A);
R.push_back(B);
return B;
}
int main() {
int T;
assert(1 == scanf("%d", &T));
for (int i = 1; i <= T; i++)
run_scenario();
}