Submission #341942

#TimeUsernameProblemLanguageResultExecution timeMemory
341942bigDuckUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
2 ms620 KiB
#include "messy.h" #include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount /* add_element("0"); compile_set(); check_element("0"); */ string s; void build(int tl, int tr){ int mid=(tl+tr)>>1ll; for(int i=tl ;i<=mid; i++){ s[i-1]='1'; add_element(s); s[i-1]='0'; } if(tl==tr){ return; } for(int i=tl; i<=mid; i++){ s[i-1]='1'; } build(mid+1, tr); for(int i=mid+1; i<=tr; i++){ s[i-1]='1'; } for(int i=tl; i<=mid; i++){ s[i-1]='0'; } build(tl, mid); } vector<int> seg[1001]; void build_seg(int v, int tl, int tr,int n){ if(tl==tr){ return; } int mid=(tl+tr)>>1ll; for(int i=0; i<n; i++){ if(s[i]=='0'){ s[i]='1'; bool res=check_element(s); if(res){ seg[v*2].pb(i); } s[i]='0'; } } for(int i:seg[v*2]){ s[i]='1'; } for(int i=0; i<n; i++){ if(s[i]=='0'){ seg[2*v+1].pb(i); } } build_seg(v*2+1, mid+1, tr, n); for(int i:seg[2*v+1]){ s[i]='1'; } for(int i:seg[2*v]){ s[i]='0'; } build_seg(2*v, tl, mid, n); } void nulify( int n){ for(int i=0; i<n; i++){ s[i]='0'; } } vector<int> res; void get_all(int v, int tl, int tr){ if(tl==tr){ res[seg[v][0] ]=tl-1; return; } get_all(2*v, tl, (tl+tr)>>1ll); get_all(2*v+1, ((tl+tr)>>1ll)+1, tr); } std::vector<int> restore_permutation(int n, int w, int r) { s.resize(n); for(int i=0; i<n; i++){ s[i]='0'; } build(1, n); //cout<<"b1"<<"\n"<<flush; compile_set(); //cout<<"c\n"<<flush; nulify(n); //cout<<"n\n"<<flush; build_seg(1, 1, n, n); //cout<<"b2\n"<<flush; res.resize(n); get_all(1, 1, n); //cout<<"g\n"<<flush; return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...