# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
358387 | 2021-01-25T12:05:20 Z | Ahmad_Hasan | Data Transfer (IOI19_transfer) | C++17 | 0 ms | 0 KB |
#include "transfer.h" #include <iostream> using namespace std; vector<int> get_attachment(vector<int>src){ if(src.size()<=30) return src; long long p=31; long long mod=1e9+7; long long ppow=1ll; long long hsh=0ll; int n=src.size(); for(int i=0;i<n;i++){ hsh+=src[i]*ppow; hsh%=mod; ppow*=p; ppow%=mod; } vector<int>ret(30); for(int i=0;i<30;i++)ret[i]=!!(hsh&(1<<i)); return ret; } vector<int> retrieve(vector<int>data){ vector<int>ret; if(data.size()<=60){ int n=data.size(); for(int i=n/2;i<n;i++) ret.push_back(data[i]); }else{ long long p=31; long long mod=1e9+7; long long ppow=1ll; long long hsh=0ll; int n=data.size()-30; vector<int>ret; for(int i=0;i<n;i++){ hsh+=data[i]*ppow; hsh%=mod; ppow*=p; ppow%=mod; } int f=0; for(int i=n;i<data.size();i++){ if(data[i]!=!!(hsh&(1<<(i-n)))) f=1; } if(!f){ for(int i=0;i<n;i++){ ret.push_back(data[i]); } return ret; } for(int i=0;i<n;i++){ data[i]=!data[i]; p=31; mod=1e9+7; ppow=1ll; hsh=0ll; for(int i=0;i<n;i++){ hsh+=data[i]*ppow; hsh%=mod; ppow*=p; ppow%=mod; } int f=0; for(int i=n;i<data.size();i++){ if(data[i]!=!!(hsh&(1<<(i-n)))) f=1; } if(!f){ for(int i=0;i<n;i++){ ret.push_back(data[i]); } return ret; } data[i]=!data[i]; } for(int i=0;i<n;i++){ ret.push_back(data[i]); } return ret; } return ret; } static inline string run_scenario() { int c; cin >> c; if (c < -1) return "invalid corruption index"; string source_str; cin >> source_str; const int N = source_str.size(); const int max_attachment_size = 2*N; vector<int> source; for (int i=0; i<N; i++) source.push_back(source_str[i]-'0'); vector<int> attachment = get_attachment(source); if (int(attachment.size()) > max_attachment_size) return "attachment too large"; for (int x : attachment) if (x != 0 && x != 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) return "wrong source retrieval"; return string("OK K=")+to_string(attachment.size()); } int main() { int T; cin >> T; for (int scenario = 0; scenario < T; scenario++) { string result = run_scenario(); cout << "scenario #" << scenario << ": " << result << endl; } return 0; }