이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "communication.h"
void encode(int N, int X)
{
X--;
int Y = X;
mt19937_64 rng(1832);
set<int>S;
for (int t = 0; t < 1000; t++)
{
int i = rng() % 250;
if (S.count(i) || S.count(i - 1) || S.count(i + 1))
continue;
S.insert(i);
}
bool ok = true;
for (int i = 0; i < 250; i++)
{
if (S.count(i))
{
int v = 0;
int x = send(v);
ok = (v == x);
}
else if (S.count(i - 1))
{
if (ok)
{
send(X % 2);
X /= 2;
}
else
{
send(Y % 2);
Y /= 2;
}
}
else
{
int x = send(rng() % 2);
}
}
}
pair<int, int> decode(int N)
{
mt19937_64 rng(1832);
set<int>S;
for (int t = 0; t < 1000; t++)
{
int i = rng() % 250;
if (S.count(i) || S.count(i - 1) || S.count(i + 1))
continue;
S.insert(i);
}
int a = 0;
int b = 0;
int ba = 1;
int bb = 1;
bool ok = true;
int cnta = 0;
int cntb = 0;
for (int i = 0; i < 250; i++)
{
int rec = receive();
if (S.count(i))
{
int v = 0;
int x = rec;
ok = (v == x);
}
else if (S.count(i - 1))
{
if (ok)
{
if (cnta < 30)
{
a += rec * ba;
ba *= 2;
cnta++;
}
}
else
{
if (cntb < 30)
{
b += rec * bb;
bb *= 2;
cntb++;
}
}
}
}
a = max(a, 0);
a = min(a, N - 1);
b = max(b, 0);
b = min(b, N - 1);
return {a + 1, b + 1};
}
// int main()
// {
// encode(15, 5);
// pair<int, int>v = decode(15);
// cout << v.first << " " << v.second << endl;
// }
컴파일 시 표준 에러 (stderr) 메시지
communication.cpp: In function 'void encode(int, int)':
communication.cpp:41:8: warning: unused variable 'x' [-Wunused-variable]
41 | int x = send(rng() % 2);
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |