Submission #443430

#TimeUsernameProblemLanguageResultExecution timeMemory
443430chicken337Data Transfer (IOI19_transfer)C++14
100 / 100
69 ms2540 KiB
#include <bits/stdc++.h> #include "transfer.h" using namespace std; vector<int> get_attachment(vector<int> source){ vector<int> ans; int xr = 0; for(int i = 0; i < source.size(); i ++) xr ^= source[i] * (i+1); int last = 0, rounds = source.size() < 64 ? 6 : 8; for(int i = 0; i < rounds; i ++){ ans.push_back(xr & 1); if(xr & 1) last ^= 1; xr >>= 1; } ans.push_back(last); return ans; } vector<int> retrieve(vector<int> data){ int last = data.back(); data.pop_back(); int actual = 0, xr = 0; int rounds = data.size() < 71 ? 6 : 8; for(int i = 0; i < rounds; i ++){ xr <<= 1; xr += data.back(); if(data.back()) last ^= 1; data.pop_back(); } if(actual != last) return vector<int>(data.begin(), data.end()); int x = 0; for(int i = 0; i < data.size(); i ++) x ^= data[i] * (i+1); int err = xr ^ x; if(err) data[err-1] ^= 1; return data; } /** int main(){ for(int i = 0; i < 100; i ++){ bool correct = true; vector<int> gen_seq; int len = rand() % 255 + 1; for(int i = 0; i < len; i ++) gen_seq.push_back(rand()&1); cout << "Generation OK" << endl; vector<int> attach = get_attachment(gen_seq); if(len < 64 && attach.size()>7) correct = 0; if(len > 63 && attach.size()>9) correct = 0; cout << "Attachment OK" << endl; vector<int> nans; for(int it : gen_seq) nans.push_back(it); for(int it : attach) nans.push_back(it); vector<int> res = retrieve(nans); cout << "Retrieval OK" << endl; if(res.size() != len) correct = 0, cout << "WRONG LENGTH" << endl; else for(int i = 0; i < res.size(); i ++) if(res[i] != gen_seq[i]) correct = 0, cout << "WRONG ELEMENT" << endl; cout << (correct ? "CORRECT" : "INCORRECT") << " with length " << len << endl; } }**/

Compilation message (stderr)

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:7:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int i = 0; i < source.size(); i ++)
      |                    ~~^~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < data.size(); i ++)
      |                    ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...