# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
829567 | Blagoj | Data Transfer (IOI19_transfer) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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());
}