Submission #818187

# Submission time Handle Problem Language Result Execution time Memory
818187 2023-08-10T03:30:07 Z LIF Data Transfer (IOI19_transfer) C++14
0 / 100
6 ms 4488 KB
#include "transfer.h"
using namespace std;
int n;
vector<int> get_attachment(vector<int> source)
{
	int ans = 0;
	n = source.size();
	int need;
	if(n == 63)need = 6;
	else need = 8;
	for(int i=0;i<source.size();i++)if(source[i] == 1)ans ^= i;
	vector<int> temp;
	for(int i=0;i<need;i++)temp.push_back(0);
	int nowbit = 0;
	while(ans > 0)
	{
		if(ans %2 == 0)temp[nowbit] = 0;
		else temp[nowbit] = 1;
		nowbit++;
		ans /= 2;
	}
	int kk = 0;
	for(int i=temp.size()-1;i>=0;i--)source.push_back(temp[i]);
	for(int i=n;i<source.size();i++)kk ^= source[i];
	source.push_back(kk);
	return source;
}
vector<int> retrieve(vector<int> data)
{
	int temp;
	for(int i=n;i<data.size()-1;i++)temp ^= data[i];
	if(temp == data[data.size()-1]) // the part of ans1 has been changed.
	{
		int suxor = 0;
		int nowbit = 1;
		for(int i=data.size()-2;i>=n;i--)
		{
			if(data[i] == 1)suxor += nowbit;
			nowbit *= 2;
		}
		vector<int> ans;
		for(int i=0;i<n;i++)
		{
			int thispos = 0;
			for(int j=0;j<n;j++)if(j!=i && data[j] == 1)thispos ^= j;
			if(thispos == suxor)
			{
				for(int k=0;k<n;k++)
				{
					if(k == i)ans.push_back(0);
					else ans.push_back(data[k]);
				}
				break;
			}
			thispos = i;
			for(int j=0;j<n;j++)if(data[j] == 1 && j!= i)thispos ^= j;
			if(thispos == suxor)
			{
				for(int k=0;k<n;k++)
				{
					if(k == i)ans.push_back(1);
					else ans.push_back(data[k]);
				}
				break;
			}
			return ans;
		}
	}
	else
	{
		vector<int> ans;
		for(int i=0;i<n;i++)ans.push_back(data[i]);
		return ans;
	}
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i=0;i<source.size();i++)if(source[i] == 1)ans ^= i;
      |              ~^~~~~~~~~~~~~~
transfer.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i=n;i<source.size();i++)kk ^= source[i];
      |              ~^~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=n;i<data.size()-1;i++)temp ^= data[i];
      |              ~^~~~~~~~~~~~~~
transfer.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
   75 | }
      | ^
transfer.cpp:32:2: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |  if(temp == data[data.size()-1]) // the part of ans1 has been changed.
      |  ^~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 912 KB WA in grader: wrong source retrieval
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4488 KB WA in grader: wrong source retrieval
2 Halted 0 ms 0 KB -