| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1353845 | 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 = recieve();
int b = recieve();
int c = recieve();
ind d = recieve();
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};
}