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 "communication.h"
#include <vector>
#include <iostream>
#include <numeric>
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;
#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};
void filterPoss(vi &poss, pii &areas)
{
vi newPoss;
for (int i = 0, idx; i < sz(poss); ++i)
{
idx = (4 * i) / sz(poss);
if (idx == areas.first || idx == areas.second)
newPoss.push_back(poss[i]);
}
swap(newPoss, poss);
}
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)
{
// cout << "Mes: " << messa[i] << " & " << e << " & " << m << endl;
ans.push_back(i);
}
}
// cout << "size of ans: " << sz(ans) << endl;
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)
{
vi poss(N, 0);
iota(all(poss), 0);
while (sz(poss) > 2)
{
// cout << " My Possibilies are: " << endl;
// for (int x : poss)
// cout << x << endl;
pii ans = receiveQuad();
filterPoss(poss, ans);
}
if (sz(poss) == 1)
poss.push_back(poss.front());
++poss[0], ++poss[1];
// cout << "The Answer is: " << poss[0] << " & " << poss[1] << endl;
return {poss[0], poss[1]};
}
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)
{
vi possibilities(N, 0);
iota(all(possibilities), 0);
--X;
while (sz(possibilities) > 2)
{
// cout << "My Space is: " << endl;
// for (int x : possibilities)
// cout << x << endl;
int m = 0; // correct quarter
for (int i = 0; i < sz(possibilities); ++i)
if (possibilities[i] == X)
m = (4 * i) / sz(possibilities);
// cout << "My m is : " << m << endl;
vi rec = sendQuad(m);
pii ans = evalQuad(rec);
filterPoss(possibilities, ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |