#include "communication.h"
#include <vector>
#include <iostream>
#include <numeric>
#include <cassert>
using namespace std;
//
// --- Sample implementation for the task communication ---
//
// To compile this program with the sample grader, place:
// communication.h communication_sample.cpp sample_grader.cpp
// in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory,
// left click on "Open in terminal") and enter e.g.:
// g++ -std=c++17 communication_sample.cpp sample_grader.cpp
// in this folder. This will create a file a.out in the current directory which you can execute from the terminal
// as ./a.out
// See task statement or sample_grader.cpp for the input specification
//
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
vi messa = {0b0000, 0b1001, 0b0110, 0b1111};
vi errors = {0, 1, 2, 4, 5, 8, 9, 10};
vpii genIntervalls(int N)
{
int size = 4;
while (size < N)
size *= 2;
return {make_pair(0, size / 2), make_pair(size / 2, size)};
}
void splitInter(vpii &inter)
{
assert(sz(inter) == 2);
vpii ni;
for (pii i : inter)
{
int m = (i.first + i.second) / 2;
ni.push_back({i.first, m});
ni.push_back({m, i.second});
}
swap(ni, inter);
}
void filterPoss(vpii &inter, pii &areas)
{
vpii ni = {inter[areas.first], inter[areas.second]};
swap(ni, inter);
}
pii evalQuad(vi &rec)
{
int m = 0;
for (int i = 0; i < 4; ++i)
m = (m << 1) | rec[i];
vi ans(0);
for (int i = 0; i < sz(messa); ++i)
{
for (int e : errors)
if ((messa[i] ^ e) == m)
ans.push_back(i);
}
return {ans[0], ans[1]};
}
pii receiveQuad()
{
vi rec;
for (int i = 0; i < 4; ++i)
rec.push_back(receive());
return evalQuad(rec);
}
std::pair<int, int> decode(int N)
{
vpii interV = genIntervalls(N);
while ((interV[0].second - interV[0].first) > 1)
{
splitInter(interV);
// cout << "My Possibilies are: " << endl;
// for (pii i : interV)
// cout << i.first << " - " << i.second << endl;
pii ans = receiveQuad();
filterPoss(interV, ans);
}
if (interV[1].second > N)
interV[1].second = interV[0].second;
// cout << "The Answer is: " << interV[0].second << " & " << interV[1].second << endl;
return {interV[0].second, interV[1].second};
}
vi sendQuad(int x)
{
vi rec;
for (int i = 3; i >= 0; --i)
{
if (messa[x] & (1 << i))
rec.push_back(send(1));
else
rec.push_back(send(0));
}
return rec;
}
void encode(int N, int X)
{
--X;
vpii interV = genIntervalls(N);
while ((interV[0].second - interV[0].first) > 1)
{
splitInter(interV);
// cout << "My Space is: " << endl;
// for (pii i : interV)
// cout << i.first << " - " << i.second << endl;
int m = 0; // correct quarter
for (int i = 0; i < sz(interV); ++i)
if (interV[i].first <= X && X < interV[i].second)
m = i;
// cout << "My m is : " << m << endl;
vi rec = sendQuad(m);
pii ans = evalQuad(rec);
filterPoss(interV, ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1680 KB |
Output is correct |
2 |
Correct |
17 ms |
1668 KB |
Output is correct |
3 |
Correct |
12 ms |
1636 KB |
Output is correct |
4 |
Correct |
11 ms |
1816 KB |
Output is correct |
5 |
Correct |
14 ms |
1680 KB |
Output is correct |
6 |
Correct |
25 ms |
1756 KB |
Output is correct |
7 |
Correct |
44 ms |
1672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
781 ms |
1740 KB |
Output is partially correct |
2 |
Partially correct |
409 ms |
1712 KB |
Output is partially correct |
3 |
Partially correct |
498 ms |
1800 KB |
Output is partially correct |
4 |
Partially correct |
926 ms |
1804 KB |
Output is partially correct |
5 |
Partially correct |
767 ms |
1768 KB |
Output is partially correct |
6 |
Partially correct |
666 ms |
1664 KB |
Output is partially correct |
7 |
Partially correct |
2283 ms |
1736 KB |
Output is partially correct |
8 |
Partially correct |
3458 ms |
2052 KB |
Output is partially correct |
9 |
Partially correct |
3336 ms |
1972 KB |
Output is partially correct |
10 |
Partially correct |
2948 ms |
1996 KB |
Output is partially correct |
11 |
Partially correct |
2768 ms |
1904 KB |
Output is partially correct |
12 |
Partially correct |
2895 ms |
1824 KB |
Output is partially correct |
13 |
Partially correct |
2762 ms |
1848 KB |
Output is partially correct |
14 |
Partially correct |
3366 ms |
1864 KB |
Output is partially correct |
15 |
Partially correct |
1542 ms |
1740 KB |
Output is partially correct |
16 |
Partially correct |
3315 ms |
1752 KB |
Output is partially correct |
17 |
Partially correct |
908 ms |
1844 KB |
Output is partially correct |
18 |
Partially correct |
859 ms |
1756 KB |
Output is partially correct |
19 |
Partially correct |
696 ms |
1752 KB |
Output is partially correct |
20 |
Partially correct |
907 ms |
1760 KB |
Output is partially correct |
21 |
Partially correct |
868 ms |
1788 KB |
Output is partially correct |
22 |
Partially correct |
1025 ms |
1748 KB |
Output is partially correct |
23 |
Partially correct |
1366 ms |
1764 KB |
Output is partially correct |
24 |
Correct |
10 ms |
1756 KB |
Output is correct |
25 |
Correct |
13 ms |
1936 KB |
Output is correct |
26 |
Correct |
14 ms |
1804 KB |
Output is correct |
27 |
Correct |
9 ms |
1724 KB |
Output is correct |
28 |
Correct |
12 ms |
1684 KB |
Output is correct |
29 |
Correct |
24 ms |
1780 KB |
Output is correct |
30 |
Correct |
48 ms |
1692 KB |
Output is correct |