Submission #829567

# Submission time Handle Problem Language Result Execution time Memory
829567 2023-08-18T12:56:07 Z Blagoj Data Transfer (IOI19_transfer) C++17
Compilation error
0 ms 0 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);
		source.push_back(sum);
	}
	int last = 0;
	for (auto x : extra) last ^= x;
	source.push_back(last);
	return {source};
}

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 ? 7 : 9); 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(); i++) cur |= (1 << i) * extra[i];
	int pos = num ^ cur;
	data[pos] = !data[pos];
	return vector<int>(data.begin(), data.end() - extra.size());
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:13:16: warning: '<<' in boolean context, did you mean '<'? [-Wint-in-bool-context]
   13 |    if (j && (1 << i)) {
      |             ~~~^~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:31:20: 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 = 0; i < extra.size() - 1; i++) Xor ^= extra[i];
      |                  ~~^~~~~~~~~~~~~~~~~~
transfer.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for (int j = 1; j <= data.size() - extra.size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
transfer.cpp:37:16: warning: '<<' in boolean context, did you mean '<'? [-Wint-in-bool-context]
   37 |    if (j && (1 << i)) {
      |             ~~~^~~~~
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 < extra.size(); i++) cur |= (1 << i) * extra[i];
      |                  ~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cclcPswZ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrtsk2X.o:transfer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status