Submission #143622

#TimeUsernameProblemLanguageResultExecution timeMemory
143622zoomswkData Transfer (IOI19_transfer)C++17
100 / 100
716 ms2716 KiB
#include "transfer.h"
using namespace std;

vector<int> get_attachment(vector<int> source) {
    int n = (int)source.size();
    vector<int> ret;
    int tmp = 0;
    for(int i=0; i<n; i++) tmp ^= source[i];
    ret.push_back(tmp);
    source.push_back(tmp);
    int bits = 6;
    if(n == 255) bits = 8;
    for(int i=1; i<=bits; i++){
        int tmp = 0;
        for(int j=0; j<=n; j++){
            if((j%(1<<i)) >= (1<<i)/2) tmp ^= source[j];
        }
        ret.push_back(tmp);
    }
    return ret;
}

vector<int> retrieve(vector<int> data) {
    vector<int> ret;
    int n = (int)data.size();
    int bits = 6;
    if(n == 255+9) bits = 8;
    n -= bits;
    int faulty = 0;
    for(int i=1; i<=bits; i++){
        int tmp = 0;
        for(int j=0; j<n; j++){
            if((j%(1<<i)) >= (1<<i)/2) tmp ^= data[j];
        }
        if(tmp != data[n+i-1]) faulty += (1<<(i-1));
    }
    for(int i=0; i<n-1; i++) ret.push_back(data[i]);
    if(faulty != n-1){
        int tmp = 0;
        for(int i=0; i<n-1; i++) tmp ^= data[i];
        if(tmp != data[n-1]){
            ret[faulty] ^= 1;
        }
    }
    return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...