#include <bits/stdc++.h>
#include <bitset>
using namespace std;
vector<bool> send_packet(vector<bool> A);
void send_message(vector<bool> M, vector<bool> C){
for(int i=0;i<16;i++){
vector<bool>enviar(31,!C[i]);
send_packet(enviar);
}
vector<bool>enviar(31,false);
int cnt=0;
for(int i=0;i<31;i++){
if(cnt==15){
break;
}
if(!C[i]){
enviar[i]=(!C[cnt+16]);
cnt++;
}
}
send_packet(enviar);
enviar.resize(31,false);
int bit=0;
int sizes=M.size();
for(int i=0;i<31;i++){
if(C[i]){
continue;
}
else{
if(((sizes)&(1<<bit))==(1<<bit)){
enviar[i]=1;
//cout<<bit<<" ";
}
else{
enviar[i]=0;
}
bit++;
}
}
//cout<<"\n";
send_packet(enviar);
vector<bool>envio;
int pos=0;
while(pos<M.size()){
if(C[envio.size()]==0){
envio.push_back(M[pos]);
pos++;
}
else{
envio.push_back(0);
}
if(envio.size()==31){
send_packet(envio);
envio.clear();
}
}
while(envio.size()<31){
envio.push_back(false);
if(envio.size()==31){
send_packet(envio);
break;
}
}
}
vector<bool> receive_message(vector<vector<bool>> R){
vector<bool>funciona(31,false);
for(int i=0;i<16;i++){
int votos=0;
for(int j=0;j<31;j++){
if(R[i][j]){
votos++;
}
}
if(votos>15){
funciona[i]=true;
}
}
int cnt=0;
for(int i=0;i<31;i++){
if(cnt==15){
break;
}
if(funciona[i]){
funciona[cnt+16]=R[16][i];
cnt++;
}
}
/*
for(bool res:R[17]){
cout<<res<<" ";
}
cout<<"\n";
*/
int bit=0;
int largo=0;
for(int i=0;i<31;i++){
if(!funciona[i]){
continue;
}
else{
if(R[17][i]==true){
largo+=(1<<bit);
}
bit++;
}
}
vector<bool>sec;
for(int i=18;i<R.size();i++){
for(int j=0;j<31;j++){
if(funciona[j]){
sec.push_back(R[i][j]);
}
}
}
while(sec.size()>largo){
sec.pop_back();
}
return sec;
}
/*
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();
}
*/
Compilation message
message.cpp: In function 'void send_message(std::vector<bool>, std::vector<bool>)':
message.cpp:44:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while(pos<M.size()){
| ~~~^~~~~~~~~
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:108:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int i=18;i<R.size();i++){
| ~^~~~~~~~~
message.cpp:115:18: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
115 | while(sec.size()>largo){
| ~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
656 KB |
Used 19 days |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
412 ms |
916 KB |
Used 23 days |
2 |
Correct |
375 ms |
828 KB |
Used 22 days |
3 |
Correct |
429 ms |
1088 KB |
Used 23 days |
4 |
Correct |
444 ms |
824 KB |
Used 22 days |
5 |
Correct |
309 ms |
832 KB |
Used 23 days |
6 |
Correct |
215 ms |
1084 KB |
Used 22 days |
7 |
Correct |
243 ms |
836 KB |
Used 22 days |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
656 KB |
Used 19 days |
2 |
Correct |
412 ms |
916 KB |
Used 23 days |
3 |
Correct |
375 ms |
828 KB |
Used 22 days |
4 |
Correct |
429 ms |
1088 KB |
Used 23 days |
5 |
Correct |
444 ms |
824 KB |
Used 22 days |
6 |
Correct |
309 ms |
832 KB |
Used 23 days |
7 |
Correct |
215 ms |
1084 KB |
Used 22 days |
8 |
Correct |
243 ms |
836 KB |
Used 22 days |
9 |
Partially correct |
1558 ms |
856 KB |
Used 83 days |
10 |
Partially correct |
928 ms |
1092 KB |
Used 82 days |
11 |
Partially correct |
1513 ms |
848 KB |
Used 83 days |
12 |
Partially correct |
1537 ms |
828 KB |
Used 82 days |
13 |
Partially correct |
1465 ms |
852 KB |
Used 82 days |
14 |
Partially correct |
1033 ms |
832 KB |
Used 83 days |
15 |
Partially correct |
829 ms |
824 KB |
Used 83 days |
16 |
Partially correct |
1127 ms |
832 KB |
Used 82 days |
17 |
Partially correct |
1124 ms |
1084 KB |
Used 82 days |
18 |
Correct |
382 ms |
824 KB |
Used 25 days |
19 |
Correct |
495 ms |
1088 KB |
Used 31 days |
20 |
Correct |
617 ms |
832 KB |
Used 37 days |
21 |
Correct |
768 ms |
1084 KB |
Used 44 days |
22 |
Correct |
891 ms |
1088 KB |
Used 50 days |
23 |
Correct |
964 ms |
1088 KB |
Used 56 days |
24 |
Correct |
1094 ms |
852 KB |
Used 62 days |
25 |
Partially correct |
1156 ms |
1088 KB |
Used 68 days |
26 |
Partially correct |
1286 ms |
832 KB |
Used 75 days |
27 |
Partially correct |
1457 ms |
848 KB |
Used 81 days |
28 |
Partially correct |
1466 ms |
852 KB |
Used 83 days |