#include"communication.h"
#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
int aux[] = {0b0000, 0b1001, 0b0110};
int get_bad(int x) {
vi ans;
for(int k = 0; k < 3; k++)
if(x == aux[k])
ans.PB(k);
for(int i = 0; i < 4; i++) {
int y = x ^ (1 << i);
for(int k = 0; k < 3; k++)
if(y == aux[k])
ans.PB(k);
for(int j = 0; j < i - 1; j++) {
int z = y ^ (1 << j);
for(int k = 0; k < 3; k++)
if(z == aux[k])
ans.PB(k);
}
}
for(int i = 0; i < 3; i++)
if(count(ALL(ans), i) == 0)
return i;
throw;
};
void encode(int n, int x) {
x--;
auto send_3 = [&] (int y) {
assert(0 <= y && y < 3);
int sent = 0;
for(int i = 0; i < 4; i++)
sent |= send(aux[y] >> i & 1) << i;
#ifdef CHEISSMART
assert(get_bad(sent) != y);
#endif
return get_bad(sent);
};
function<void(int)> go = [&] (int m) { // [0, m);
assert(x < m);
if(m <= 3) {
send_3(x);
return;
}
int he = m / 3, be = he * 2;
// [0, he), [he, be), [be, m)
if(x < he) {
int bad = send_3(0);
if(bad == 1) go(he + m - be);
else if(bad == 2) go(be);
else throw;
} else if(x < be) {
int bad = send_3(1);
if(bad == 0) {
x -= he;
go(m - he);
} else if(bad == 2) {
go(be);
} else throw;
} else {
int bad = send_3(2);
if(bad == 0) {
x -= he;
go(m - he);
} else if(bad == 1) {
x -= be - he;
go(he + m - be);
} else throw;
}
};
go(n);
}
pi decode(int n) {
auto get_3 = [&] () {
int x = 0;
for(int i = 0; i < 4; i++)
x |= receive() << i;
return get_bad(x);
};
function<pi(int)> go = [&] (int m) -> pi { // [0, m);
if(m <= 3) {
int bad = get_3();
if(bad == 0) return {1, 2};
else if(bad == 1) return {0, 2};
else return {0, 1};
}
int he = m / 3, be = he * 2;
// [0, he), [he, be), [be, m)
int bad = get_3();
if(bad == 0) {
auto [x, y] = go(m - he);
x += he, y += he;
return {x, y};
} else if(bad == 1) {
auto [x, y] = go(he + m - be);
if(x >= he) x += be - he;
if(y >= he) y += be - he;
return {x, y};
} else {
auto [x, y] = go(be);
return {x, y};
}
};
auto[x, y] = go(n);
return {x + 1, y + 1};
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1728 KB |
Output is correct |
2 |
Correct |
15 ms |
1708 KB |
Output is correct |
3 |
Correct |
16 ms |
1812 KB |
Output is correct |
4 |
Correct |
10 ms |
1748 KB |
Output is correct |
5 |
Correct |
13 ms |
1736 KB |
Output is correct |
6 |
Correct |
27 ms |
1784 KB |
Output is correct |
7 |
Correct |
38 ms |
1668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1274 ms |
1876 KB |
Output is partially correct |
2 |
Partially correct |
644 ms |
1780 KB |
Output is partially correct |
3 |
Partially correct |
892 ms |
1692 KB |
Output is partially correct |
4 |
Partially correct |
1548 ms |
1812 KB |
Output is partially correct |
5 |
Partially correct |
1370 ms |
1788 KB |
Output is partially correct |
6 |
Partially correct |
1035 ms |
1808 KB |
Output is partially correct |
7 |
Partially correct |
3844 ms |
1828 KB |
Output is partially correct |
8 |
Partially correct |
5774 ms |
2040 KB |
Output is partially correct |
9 |
Partially correct |
4951 ms |
1988 KB |
Output is partially correct |
10 |
Partially correct |
5445 ms |
1980 KB |
Output is partially correct |
11 |
Partially correct |
5129 ms |
1924 KB |
Output is partially correct |
12 |
Partially correct |
5340 ms |
1888 KB |
Output is partially correct |
13 |
Partially correct |
5220 ms |
1976 KB |
Output is partially correct |
14 |
Partially correct |
4827 ms |
1984 KB |
Output is partially correct |
15 |
Partially correct |
2557 ms |
1908 KB |
Output is partially correct |
16 |
Partially correct |
5776 ms |
1856 KB |
Output is partially correct |
17 |
Partially correct |
1250 ms |
1836 KB |
Output is partially correct |
18 |
Partially correct |
1506 ms |
1964 KB |
Output is partially correct |
19 |
Partially correct |
1461 ms |
1916 KB |
Output is partially correct |
20 |
Partially correct |
1395 ms |
1884 KB |
Output is partially correct |
21 |
Partially correct |
1392 ms |
1880 KB |
Output is partially correct |
22 |
Partially correct |
1502 ms |
1956 KB |
Output is partially correct |
23 |
Partially correct |
2352 ms |
1736 KB |
Output is partially correct |
24 |
Correct |
12 ms |
1600 KB |
Output is correct |
25 |
Correct |
13 ms |
1744 KB |
Output is correct |
26 |
Correct |
16 ms |
1636 KB |
Output is correct |
27 |
Correct |
12 ms |
1824 KB |
Output is correct |
28 |
Correct |
9 ms |
1728 KB |
Output is correct |
29 |
Correct |
25 ms |
1812 KB |
Output is correct |
30 |
Correct |
45 ms |
1664 KB |
Output is correct |