답안 #909774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909774 2024-01-17T12:02:09 Z BBart888 Data Transfer (IOI19_transfer) C++14
0 / 100
6 ms 5756 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 = source;
	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 ^= (1 << i);

	int error = actual_x ^ x;
	if (error == 0)
		return data;

	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++)
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 1296 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 5756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -