답안 #829606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829606 2023-08-18T13:19:07 Z Blagoj Data Transfer (IOI19_transfer) C++17
0 / 100
6 ms 3088 KB
#include <bits/stdc++.h>
#include "transfer.h"
// #include "grader.cpp"

using namespace std;

vector<int> get_attachment(vector<int> source) {
	int n = source.size();
	vector<int> extra;
	for (int i = 0; i < (n == 63 ? 6 : 8); i++) {
		int sum = 0;
		for (int j = 1; j <= n; j++) {
			if (j & (1 << i)) {
				sum ^= source[j - 1];
			}
		}
		extra.push_back(sum);
	}
	int last = 0;
	for (auto x : extra) last ^= x;
	extra.push_back(last);
	return {extra};
}

vector<int> retrieve(vector<int> data) {
	vector<int> extra;
	for (int i = data.size() - 1; (i > 62 && i <= 70) || (i > 254 && i <= 300); i--) extra.push_back(data[i]);
	reverse(extra.begin(), extra.end());
	int Xor = 0;
	for (int i = 0; i < extra.size() - 1; i++) Xor ^= extra[i];
	if (Xor != extra.back()) return vector<int>(data.begin(), data.end() - extra.size());
	int num = 0;
	for (int i = 0; i < ((data.size() - extra.size()) == 63 ? 6 : 8); i++) {
		int sum = 0;
		for (int j = 1; j <= data.size() - extra.size(); j++) {
			if (j & (1 << i)) {
				sum ^= data[j - 1];
			}
		}
		num |= (1 << i) * sum;
	}
	int cur = 0;
	for (int i = 0; i < extra.size() - 1; i++) cur |= (1 << i) * extra[i];
	int pos = num ^ cur;
	data[pos - 1] = !data[pos - 1];
	while (extra.size()) {
		extra.pop_back();
		data.pop_back();
	}
	return data;
}

Compilation message

transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 0; i < extra.size() - 1; i++) Xor ^= extra[i];
      |                  ~~^~~~~~~~~~~~~~~~~~
transfer.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int j = 1; j <= data.size() - extra.size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
transfer.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0; i < extra.size() - 1; i++) cur |= (1 << i) * extra[i];
      |                  ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 900 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3088 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -