| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1353846 | lukaye_19 | Flight to the Ford (BOI22_communication) | C++20 | 0 ms | 0 KiB |
#include "communication.h"
#include <bits/stdc++.h>
using namespace std;
void encode(long long N,long long X)
{
string binary = "";
for (int i = 0; i < 30; i++)
{
int op = X % 2;
X /= 2;
binary.push_back((char)(op + '0'));
}
for (char x : binary)
{
int op = x - '0';
if (op == 1)
{
send(1);
send(0);
send(0);
send(1);
}
else
{
send(0);
send(0);
send(0);
send(0);
}
}
}
pair<int,int> decode(long long N)
{
string binary = "";
for (int i = 0; i < 30; i++)
{
int a = receive();
int b = receive();
int c = receive();
int d = receive();
vector<int>v = {a,b,c,d};
int X;
if (v[0] == v[3])
{
if (v[0] == 1) X = 2;
else X = 1;
}
else if (v[0] == v[1])
{
X = 2;
}
else
{
X = 1;
}
X--;
binary.push_back((char)(X + '0'));
}
long long R = 0;
for (int i = 0; i < 30; i++)
{
R += (long long)pow(2,i) * (binary[i] - '0');
}
return {N,R};
}