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>
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |