#include <bits/stdc++.h>
#include "transfer.h"
using namespace std;
vector<int> get_attachment(vector<int> source) {
int n = source.size();
int B = 8;
if (n == 63) B = 6;
vector<int> ans(B);
int sum = 0;
for (int i = 0; i < B; i++) {
for (int j = 1; j <= n; j++) {
if ((j & (1 << i)) && source[j - 1]) ans[i]++;
}
ans[i] %= 2;
sum += ans[i];
}
sum %= 2;
ans.push_back(sum);
return ans;
}
vector<int> retrieve(vector<int> data) {
int B = 8;
if (((int) data.size()) == 70) B = 6;
vector<int> ot;
for (int i = 0; i <= B; i++) {
ot.push_back(data.back());
data.pop_back();
}
reverse(ot.begin(), ot.end());
int sum = 0;
for (int i = 0; i < B; i++) sum = ((sum + ot[i])%2);
if (sum != ot[B]) return data;
int n = data.size();
int ans = 0;
for (int i = 0; i < B; i++) {
int curr = 0;
for (int j = 1; j <= n; j++) {
if ((j & (1 << i)) && data[j - 1]) curr++;
}
curr %= 2;
if (curr != ot[i]) ans += (1 << i);
}
if (ans == 0) return data;
data[ans - 1] = (1 - data[ans - 1]);
return data;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |