# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
829691 | bane | Data Transfer (IOI19_transfer) | C++17 | 106 ms | 2496 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 "transfer.h"
#include<vector>
using namespace std;
std::vector<int> get_attachment(std::vector<int> source) {
int tot = 0;
if (source.size() <= 63)tot = 6;
else tot = 8;
vector<int>adding(tot + 1, 0);
int odd = 0;
for (int i = 0; i < source.size(); i++){
odd += source[i];
}
adding.back() = odd & 1;
int a = 0;
for (int i = 0; i < source.size(); i++){
if (source[i]){
a ^= (i + 1);
}
}
for (int j = 0; j < tot; j++){
if (a & (1 << j))adding[j] = 1;
}
return adding;
}
std::vector<int> retrieve(std::vector<int> data) {
if (data.size() > 100){
int odd = 0;
for (int i = 0 ; i < 255; i++){
odd += data[i];
}
odd = odd & 1;
int xr = 0, xr2 = 0;
for (int i = 0; i < 8; i++){
if (data[255 + i])xr2 ^= (1 << i);
}
for (int i = 0; i < 255; i++){
if (data[i])xr ^= (i + 1);
}
int ok = (xr == xr2);
if (!ok){
if (odd != data.back()){
//first half is fucked
for (int i = 0; i < 255; i++){
if ((xr ^ (i + 1)) == xr2){
data[i] ^= 1;
//return data;
}
}
}else{
//second half is fucked
for (int i = 0; i < 8; i++){
if (((1 << i) ^xr2) == xr){
data[255 + i] ^= 1;
//return data;
}
}
}
}else{
data.back() ^= 1;
}
vector<int>ans;
for (int i = 0; i < 255; i++)ans.push_back(data[i]);
return ans;
}else{
int odd = 0;
for (int i = 0 ; i < 63; i++){
odd += data[i];
}
odd = odd & 1;
int xr = 0, xr2 = 0;
for (int i = 0; i < 6; i++){
if (data[63 + i])xr2 ^= (1 << i);
}
for (int i = 0; i < 63; i++){
if (data[i])xr ^= (i + 1);
}
int ok = (xr == xr2);
if (!ok){
if (odd != data.back()){
//first half is fucked
for (int i = 0; i < 63; i++){
if ((xr ^ (i + 1)) == xr2){
data[i] ^= 1;
//return data;
}
}
}else{
//second half is fucked
for (int i = 0; i < 6; i++){
if (((1 << i) ^xr2) == xr){
data[63 + i] ^= 1;
//return data;
}
}
}
}else{
data.back() ^= 1;
//return data;
}
vector<int>ans;
for (int i = 0; i < 63; i++)ans.push_back(data[i]);
return ans;
}
return data;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |