Submission #909784

# Submission time Handle Problem Language Result Execution time Memory
909784 2024-01-17T12:11:26 Z Gryff1 Data Transfer (IOI19_transfer) C++14
100 / 100
44 ms 2932 KB
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include <cstdlib>
#include <complex>
#include <array>
#include <iomanip>
#include <bitset>
#define fileIO(name) if(fopen(name".in", "r")) {freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);}



using namespace std;
const int MAXN = 2e5 + 111;
using ll = long long;
const int P = 31;
const ll mod1 = 1e9 + 7;
const ll mod2 = 998244353;
using ld = long double;
const ld EPS = 1e-5;
using pii = pair<int, int>;
const int K = 300;


			
vector<int> get_attachment(vector<int> source)
{
	vector<int> res;
	int x = 0;

	for (int i = 0; i < source.size(); i++)
	{
		if (source[i])
			x ^= (1 + i);
	}
	int odd = 0;
	if (source.size() <= 63)
	{
		for (int i = 0; i < 6; i++)
		{
			if ((1 << i) & x)
				odd++,res.push_back(1);
			else
				res.push_back(0);
		}
		res.push_back(odd & 1);
	}
	else
	{
		for (int i = 0; i < 8; i++)
			if ((1 << i) & x)
				odd++, res.push_back(1);
			else
				res.push_back(0);
		res.push_back(odd & 1);
	}

	return res;
}


vector<int> retrieve(vector<int> data)
{
	
	int last = data.back();
	data.pop_back();
	int actual_last = 0;
	int x = 0;
	if (data.size() < 71)
	{
		for (int i = 0; i < 6; i++)
		{
			x <<= 1;
			x += data.back();
			if (data.back())
				actual_last = 1 - actual_last;
			data.pop_back();
		}
	}
	else
	{
		for (int i = 0; i < 8; i++)
		{
			x <<= 1;
			x += data.back();
			if (data.back())
				actual_last = 1 - actual_last;
			data.pop_back();
		}
	}
	
	if (last != actual_last)
		return data;

	int actual_x = 0;
	for (int i = 0; i < data.size(); i++)
		if (data[i])
			actual_x ^= (i+1);

	int error = actual_x ^ x;
	if (error == 0)
		return  std::vector<int>(data.begin(), data.end());;

	data[error - 1] = 1 - data[error - 1];

	return data;
}



Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (int i = 0; i < source.size(); i++)
      |                  ~~^~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:109:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |  for (int i = 0; i < data.size(); i++)
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 788 KB Output is correct
2 Correct 2 ms 796 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
4 Correct 2 ms 796 KB Output is correct
5 Correct 2 ms 788 KB Output is correct
6 Correct 2 ms 792 KB Output is correct
7 Correct 2 ms 788 KB Output is correct
8 Correct 1 ms 796 KB Output is correct
9 Correct 1 ms 1048 KB Output is correct
10 Correct 2 ms 788 KB Output is correct
11 Correct 2 ms 796 KB Output is correct
12 Correct 2 ms 792 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 2 ms 796 KB Output is correct
15 Correct 3 ms 788 KB Output is correct
16 Correct 2 ms 792 KB Output is correct
17 Correct 2 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2516 KB Output is correct
2 Correct 35 ms 2516 KB Output is correct
3 Correct 35 ms 2504 KB Output is correct
4 Correct 39 ms 2504 KB Output is correct
5 Correct 38 ms 2512 KB Output is correct
6 Correct 41 ms 2512 KB Output is correct
7 Correct 44 ms 2508 KB Output is correct
8 Correct 32 ms 2824 KB Output is correct
9 Correct 33 ms 2504 KB Output is correct
10 Correct 30 ms 2512 KB Output is correct
11 Correct 29 ms 2512 KB Output is correct
12 Correct 32 ms 2932 KB Output is correct
13 Correct 32 ms 2508 KB Output is correct
14 Correct 37 ms 2512 KB Output is correct
15 Correct 38 ms 2504 KB Output is correct
16 Correct 42 ms 2512 KB Output is correct
17 Correct 35 ms 2512 KB Output is correct
18 Correct 44 ms 2512 KB Output is correct
19 Correct 35 ms 2504 KB Output is correct