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>
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()
vi messa = {0b0000, 0b1001, 0b0110, 0b1111};
vi errors = {0, 1, 2, 4, 5, 8, 9, 10};
void sendQuad(int x)
{
for (int i = 3; i >= 0; --i)
{
if (messa[x] & (1 << i))
send(1);
else
send(0);
}
}
void encode(int N, int X)
{
X = (X - 1) % 4;
sendQuad(X);
}
pii receiveQuad()
{
int m = 0;
for (int i = 0; i < 4; ++i)
m = (m << 1) | receive();
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]};
}
std::pair<int, int> decode(int N)
{
pii ans = receiveQuad();
++ans.first, ++ans.second;
if (ans.second > N)
--ans.second;
// cout << "The Answer is: " << ans.first << " & " << ans.second << endl;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |