답안 #590887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590887 2022-07-06T13:09:58 Z tutis Flight to the Ford (BOI22_communication) C++17
30 / 100
6190 ms 2036 KB
#include <bits/stdc++.h>
using namespace std;
int prob = 1;
#include "communication.h"
int dec3(int x)//4 bit x
{
	vector<int>ger;
	for (int m = 0; m < 16; m++)
	{
		bool ok = true;
		int v = m;
		while (v != 0)
		{
			if (v % 4 == 3)
				ok = false;
			v /= 2;
		}
		if (ok)
			ger.push_back(m);
	}
	int V[4] = {0, 0, 6, 9};
	for (int i = 1; i <= 3; i++)
	{
		bool ok = true;
		for (int j : ger)
			if (x == (V[i] ^ j))
				ok = false;
		if (ok)
			return i;
	}
	assert(false);
	return 0;
}
int enc3(int X)
{
	int v = 0;
	if (X == 1)
		v = 0;
	else if (X == 2)
		v = 6;
	else if (X == 3)
		v = 9;
	int val = 0;
	for (int t = 0; t < 4; t++)
	{
		val += send(v % 2) << t;
		v /= 2;
	}
	return dec3(val);
}
void encode(int N, int X)
{
	if (N < 3)
		return;
	if (N == 3)
	{
		enc3(X);
		return;
	}
	int v = N / 3;
	int vv = 3;
	if (X <= v)
		vv = 1;
	else if (X <= 2 * v)
		vv = 2;
	int val = enc3(vv);
	assert(val != vv);
	if (val == 2)
	{
		if (vv == 1)
			encode(N - v, X);
		if (vv == 3)
			encode(N - v, X - v);
	}
	if (val == 1)
		encode(N - v, X - v);
	if (val == 3)
		encode(2 * v, X);
}
pair<int, int> decode(int N)
{
	if (N == 1)
		return {1, 1};
	if (N == 2)
		return {1, 2};
	if (N == 3)
	{
		int val = 0;
		for (int t = 0; t < 4; t++)
			val += receive() << t;
		int v = dec3(val);
		pair<int, int>ans = {1, 2};
		if (v == 1)
			ans.first = 3;
		if (v == 2)
			ans.second = 3;
		return ans;
	}
	else {
		int re = 0;
		for (int t = 0; t < 4; t++)
			re += receive() << t;
		int val = dec3(re);
		int v = N / 3;
		if (val == 2)
		{
			pair<int, int>r = decode(N - v);
			if (r.first > v)
				r.first += v;
			if (r.second > v)
				r.second += v;
			return r;
		}
		if (val == 1)
		{
			pair<int, int>r = decode(N - v);
			r.first += v;
			r.second += v;
			return r;
		}
		if (val == 3)
			return decode(2 * v);
	}
}
// int main()
// {
// 	vector<int>ger;
// 	for (int m = 0; m < 16; m++)
// 	{
// 		bool ok = true;
// 		int v = m;
// 		while (v != 0)
// 		{
// 			if (v % 4 == 3)
// 				ok = false;
// 			v /= 2;
// 		}
// 		if (ok)
// 			ger.push_back(m);
// 	}
// 	int a = 0;
// 	{
// 		for (int b = 0; b < 16; b++)
// 		{
// 			for (int c = 0; c < 16; c++)
// 			{
// 				if (a == b || b == c || c == a)
// 					continue;
// 				set<int>A;
// 				set<int>B;
// 				set<int>C;
// 				for (int i : ger)
// 				{
// 					A.insert(i ^ a);
// 					B.insert(i ^ b);
// 					C.insert(i ^ c);
// 				}
// 				bool ok = true;
// 				for (int i : ger)
// 				{
// 					int v1 = i ^ b;
// 					int v2 = i ^ c;
// 					if (A.count(v1) > 0 && A.count(v2) > 0)
// 					{
// 						ok = false;
// 						break;
// 					}
// 				}
// 				for (int i : ger)
// 				{
// 					int v1 = i ^ a;
// 					int v2 = i ^ c;
// 					if (B.count(v1) > 0 && B.count(v2) > 0)
// 					{
// 						ok = false;
// 						break;
// 					}
// 				}
// 				for (int i : ger)
// 				{
// 					int v1 = i ^ a;
// 					int v2 = i ^ b;
// 					if (C.count(v1) > 0 && C.count(v2) > 0)
// 					{
// 						ok = false;
// 						break;
// 					}
// 				}
// 				if (ok)
// 				{
// 					// cout << bitset<4>(a) << endl;
// 					// cout << bitset<4>(b) << endl;
// 					// cout << bitset<4>(c) << endl;
// 					// cout << endl;
// 				}
// 			}
// 		}
// 	}
// 	for (int t = 0; t < 1000; t++)
// 	{
// 		int N = 4;
// 		int val = (t % N) + 1;
// 		encode(N, val);
// 		pair<int, int>v = decode(N);
// 		cout << v.first << " " << v.second << endl;
// 		assert(v.first == val || v.second == val);
// 	}
// }

Compilation message

communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:124:1: warning: control reaches end of non-void function [-Wreturn-type]
  124 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1784 KB Output is correct
2 Correct 11 ms 1784 KB Output is correct
3 Correct 19 ms 1652 KB Output is correct
4 Correct 10 ms 1744 KB Output is correct
5 Correct 13 ms 1748 KB Output is correct
6 Correct 28 ms 1684 KB Output is correct
7 Correct 45 ms 1696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1181 ms 1664 KB Output is partially correct
2 Partially correct 633 ms 1716 KB Output is partially correct
3 Partially correct 927 ms 1776 KB Output is partially correct
4 Partially correct 1405 ms 1732 KB Output is partially correct
5 Partially correct 1107 ms 1780 KB Output is partially correct
6 Partially correct 1129 ms 1688 KB Output is partially correct
7 Partially correct 4057 ms 1920 KB Output is partially correct
8 Partially correct 6190 ms 2036 KB Output is partially correct
9 Partially correct 5005 ms 1876 KB Output is partially correct
10 Partially correct 5245 ms 1840 KB Output is partially correct
11 Partially correct 5443 ms 1844 KB Output is partially correct
12 Partially correct 4975 ms 1900 KB Output is partially correct
13 Partially correct 5213 ms 1848 KB Output is partially correct
14 Partially correct 5139 ms 1996 KB Output is partially correct
15 Partially correct 2999 ms 1804 KB Output is partially correct
16 Partially correct 5697 ms 1808 KB Output is partially correct
17 Partially correct 1436 ms 1728 KB Output is partially correct
18 Partially correct 1425 ms 1740 KB Output is partially correct
19 Partially correct 1348 ms 1940 KB Output is partially correct
20 Partially correct 1465 ms 1836 KB Output is partially correct
21 Partially correct 1424 ms 1876 KB Output is partially correct
22 Partially correct 1317 ms 1816 KB Output is partially correct
23 Partially correct 2460 ms 1728 KB Output is partially correct
24 Correct 6 ms 1720 KB Output is correct
25 Correct 10 ms 1672 KB Output is correct
26 Correct 16 ms 1664 KB Output is correct
27 Correct 10 ms 1788 KB Output is correct
28 Correct 13 ms 1724 KB Output is correct
29 Correct 18 ms 1896 KB Output is correct
30 Correct 47 ms 1720 KB Output is correct