#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#include "communication.h"
vector<int> V = {2,2,3,3,2,3,3,3,3,3,2,2,2,2,2,2,2,3,2,3,2,3,3,2,3,3,2,3,3,2,2,3,2,3,2,3,2,2,2,3,2,2,3,2,2,3,2,2,2,3};
//bool aux[250];
/*
vector<int> v;
int send(int x){
cout<<x<<" SENDED"<<endl;
int c;
cin >> c;
v.pb(c);
return c;
}
int P = 0;
int receive(){
cout<<"SEND ME"<<endl;
int c;
return v[P++];
}
*/
void encode(int N, int X) {
srand(N);
int pos = 0;
int T = 0;
int ASKED = 0;
int M = 0;
while(pos < 2){
int r_bit = 0;
if(X&(1<<pos)) r_bit = 1;
int nxt = V[T++];
T = T % ((int)V.size());
ASKED += 1 + nxt;
if(ASKED > 250) cout<<2/0<<endl;
int t = send(1);
M ^= t;
if(t == 1){
bool ok = true;
fr(i, 0, nxt){
int c = send(r_bit);
ok &= (c == r_bit);
M ^= c;
}
if(ok) ++pos;
}
else{
M ^= send(r_bit);
fr(i, 0, nxt-1) M ^= send(0);
++pos;
}
if(M) T *= 2;
T = T % ((int)V.size());
}
}
std::pair<int, int> decode(int N){
srand(N);
int pos = 0;
int X = 0;
int T = 0;
int ASKED = 0;
int M = 0;
while(pos < 2){
int nxt = V[T++];
T = T % ((int)V.size());
ASKED += 1 + nxt;
if(ASKED > 250) cout<<2/0<<endl;
int t = receive();
M ^= t;
if(t == 1){
int sum = 0;
fr(i, 0, nxt){
int c = receive();
M ^= c;
sum += c;
}
if(sum == 0) ++pos;
else if(sum == nxt){
X |= (1<<pos);
++pos;
}
}
else{
int c = receive();
M ^= c;
if(c == 1) X |= (1<<pos);
fr(i, 0, nxt-1){
M ^= receive();
}
++pos;
}
if(M) T *= 2;
T = T % ((int)V.size());
}
//cout<<X<<endl;
return {X, 2};
}/*
int main(){
encode(10, 1);
decode(10);
}
*/
Compilation message
communication.cpp: In function 'void encode(int, int)':
communication.cpp:56:26: warning: division by zero [-Wdiv-by-zero]
56 | if(ASKED > 250) cout<<2/0<<endl;
| ~^~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:98:26: warning: division by zero [-Wdiv-by-zero]
98 | if(ASKED > 250) cout<<2/0<<endl;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1748 KB |
Output is correct |
2 |
Correct |
16 ms |
1696 KB |
Output is correct |
3 |
Runtime error |
2 ms |
292 KB |
Execution killed with signal 4 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
78 ms |
200 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |