#include "transfer.h"
std::vector<int> get_attachment(std::vector<int> source) {
const int n = source.size();
int sum = 0;
for (int i = 0; i < n; ++i) {
sum ^= source[i] * (i + 1);
}
const int k = n == 63 ? 6 : 8;
std::vector<int> ret(k + 1);
int bit = 0;
for (int i = 0; i < k; ++i) {
ret[i] = sum >> i & 1;
bit ^= ret[i];
}
ret[k] = bit;
return ret;
}
std::vector<int> retrieve(std::vector<int> data) {
const int n = data.size();
const int k = n == 70 ? 6 : 8;
const int m = n - k - 1;
std::vector<int> ret(data.begin(), data.begin() + m);
int sum = 0, bit = 0;
for (int i = 0; i < k; ++i) {
sum += data[m + i] << i;
bit ^= data[m + i];
}
if (bit != ret[m + k]) {
return ret;
}
int actual = 0;
for (int i = 0; i < m; ++i) {
actual ^= data[i] * (i + 1);
}
if (actual == sum) {
return ret;
} else {
ret[(actual ^ sum) - 1] ^= 1;
return ret;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
608 KB |
WA in grader: wrong source retrieval |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2432 KB |
WA in grader: wrong source retrieval |
2 |
Halted |
0 ms |
0 KB |
- |