Submission #134665

#TimeUsernameProblemLanguageResultExecution timeMemory
134665UtahaUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
5 ms632 KiB
#include "messy.h" #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pdd; #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i,n) for(int i=0;i<((int)n);i++) #define pb emplace_back #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<'('<<P.F<<','<<P.S<<')'; return out; } #define version 20190713 //}}} const ll maxn=300005; const ll maxlg=__lg(maxn)+2; const ll INF64=8000000000000000000LL; const int INF=0x3f3f3f3f; const ll MOD=ll(1e9+7); const ld PI=acos(-1); const ld eps=1e-9; vector<int> ans; void add(int n,int l,int r,vector<int> trash){ if(l==r-1){ return; } int mid=(l+r)/2; for(int p=l;p<mid;p++){ string s; s.append(n,'0'); s[p]='1'; for(int i:trash) s[i]='1'; add_element(s); } { vector<int> tmp=trash; for(int i=l;i<mid;i++) tmp.pb(i); add(n,mid,r,tmp); } { vector<int> tmp=trash; for(int i=mid;i<r;i++) tmp.pb(i); add(n,l,mid,tmp); } } void solve(int n,int l,int r,vector<int> can,vector<int> trash,vector<int> tridx){ if(l==r-1){ ans[can[0]]=l; return; } vector<int> lc,rc; for(int p:can){ string s; s.append(n,'0'); for(int i:tridx) s[i]='1'; s[p]='1'; if(check_element(s)) lc.pb(p); else rc.pb(p); } int mid=(l+r)/2; { vector<int> tmp=trash; vector<int> tmp2=tridx; for(int i:lc) tmp2.pb(i); for(int i=l;i<mid;i++) tmp.pb(i); solve(n,mid,r,rc,tmp,tmp2); } { vector<int> tmp=trash; vector<int> tmp2=tridx; for(int i:rc) tmp2.pb(i); for(int i=mid;i<r;i++) tmp.pb(i); solve(n,l,mid,lc,tmp,tmp2); } } vector<int> restore_permutation(int N, int w, int r) { add(N,0,N,vector<int>()); compile_set(); ans.resize(N); vector<int> v; REP(i,N) v.pb(i); solve(N,0,N,v,vector<int>(),vector<int>()); return ans; }
#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...