Submission #590754

# Submission time Handle Problem Language Result Execution time Memory
590754 2022-07-06T10:15:02 Z tutis Flight to the Ford (BOI22_communication) C++17
0 / 100
667 ms 1776 KB
#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;
// }

Compilation message

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
1 Correct 197 ms 1776 KB Output is correct
2 Incorrect 146 ms 288 KB Not correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 667 ms 268 KB Not correct
2 Halted 0 ms 0 KB -