# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1006273 | Almonther | Data Transfer (IOI19_transfer) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
// #include "transfer.h"
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
vector<int>get_attachment(vector<int>source){
vector<int>arr;
ll n=source.size();
ll num=0;
ll pa=0;
for(int i=0;i<n;i++){
if(source[i]) num^=i+1;
pa^=source[i];
}
string s="";
while(num){
s+='0'+(num%2);
num>>=1;
}
reverse(s.begin(),s.end());
while(s.size()<((n==255)?8:6)) s='0'+s;
for(auto i:s) arr.push_back(i-'0');
arr.push_back(pa);
return arr;
}
vector<int>retrieve(vector<int>data){
vector<int>arr=data;
ll n=arr.size();
ll pa,pa1,num;
pa=0,pa1=0,num=0;
ll test=arr[n-1];
ll n1=((n>255)?255:63);
vector<int>ans;
for(int i=n1;i<n1+((n>255)?8:6);i++){
num=num*2+arr[i];
}
for(int i=0;i<n1;i++){
pa^=arr[i];
if(arr[i]) num^=i+1;
}
pa1=pa;
if(num){
if(arr[num-1]) pa1=((pa1-1)%2+2)%2;
else pa1=(pa1+1)%2;
if(pa1==test){
for(int i=0;i<n1;i++){
ans.push_back(arr[i]);
}
ans[num-1]^=1;
return ans;
}
else{
for(int i=0;i<n1;i++){
ans.push_back(arr[i]);
}
return ans;
}
}
else{
for(int i=0;i<255;i++){
ans.push_back(arr[i]);
}
return ans;
}
}
static inline string run_scenario() {
int c=rand()%255;
const int N = 255;
const int max_attachment_size = 2*N;
vector<int> source;
for (int i=0; i<N; i++)
source.push_back(rand()%2);
vector<int> attachment = get_attachment(source);
if (int(attachment.size()) > max_attachment_size)
return "attachment too large";
for (int i=0;i<attachment.size();i++)
if (attachment[i] != 0 && attachment[i] != 1)
return " invalid attachment integer value";
vector<int> data(source);
data.insert(data.end(), attachment.begin(), attachment.end());
if (c >= int(data.size()))
return "invalid corruption index";
if (c >= 0)
data[c] = 1-data[c];
vector<int> result_source = retrieve(data);
if (source != result_source){
for(int i=0;i<source.size();i++){
if(source[i]!=result_source[i]){
co i<<' ';
}
}
co '\n';
return "wrong source retrieval";
}
return string("OK K=")+to_string(attachment.size());
}
int main() {
srand(time(0));
int T=100;
for (int scenario = 0; scenario < T; scenario++) {
string result = run_scenario();
cout << "scenario #" << scenario+1 << ": " << result << endl;
}
return 0;
}