답안 #909783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909783 2024-01-17T12:09:05 Z Gryff1 Data Transfer (IOI19_transfer) C++14
100 / 100
48 ms 3120 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;



std::vector<int> get_attachment(std::vector<int> source) {
	std::vector<int> v;
	int x = 0;
	for (int i = 0; i < source.size(); i++)
		if (source[i]) x ^= (i + 1);

	int last = 0;
	if (source.size() < 64) {
		for (int i = 0; i < 6; i++) {
			v.push_back(x & 1);
			if (x & 1) last = 1 - last;
			x >>= 1;
		}
	}
	else {
		for (int i = 0; i < 8; i++) {
			v.push_back(x & 1);
			if (x & 1) last = 1 - last;
			x >>= 1;
		}
	}
	v.push_back(last);
	return v;
}


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:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < source.size(); i++)
      |                  ~~^~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:99:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for (int i = 0; i < data.size(); i++)
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 796 KB Output is correct
2 Correct 2 ms 800 KB Output is correct
3 Correct 2 ms 800 KB Output is correct
4 Correct 3 ms 1224 KB Output is correct
5 Correct 2 ms 884 KB Output is correct
6 Correct 2 ms 800 KB Output is correct
7 Correct 2 ms 792 KB Output is correct
8 Correct 2 ms 800 KB Output is correct
9 Correct 2 ms 792 KB Output is correct
10 Correct 2 ms 796 KB Output is correct
11 Correct 2 ms 796 KB Output is correct
12 Correct 2 ms 796 KB Output is correct
13 Correct 2 ms 800 KB Output is correct
14 Correct 1 ms 792 KB Output is correct
15 Correct 2 ms 792 KB Output is correct
16 Correct 2 ms 768 KB Output is correct
17 Correct 3 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2512 KB Output is correct
2 Correct 35 ms 2508 KB Output is correct
3 Correct 36 ms 2828 KB Output is correct
4 Correct 38 ms 2516 KB Output is correct
5 Correct 45 ms 2504 KB Output is correct
6 Correct 40 ms 2508 KB Output is correct
7 Correct 38 ms 2516 KB Output is correct
8 Correct 40 ms 2508 KB Output is correct
9 Correct 30 ms 2504 KB Output is correct
10 Correct 29 ms 2516 KB Output is correct
11 Correct 29 ms 2508 KB Output is correct
12 Correct 32 ms 2516 KB Output is correct
13 Correct 36 ms 3120 KB Output is correct
14 Correct 36 ms 2504 KB Output is correct
15 Correct 36 ms 2508 KB Output is correct
16 Correct 46 ms 2504 KB Output is correct
17 Correct 35 ms 2520 KB Output is correct
18 Correct 48 ms 2508 KB Output is correct
19 Correct 34 ms 2512 KB Output is correct