Submission #152991

#TimeUsernameProblemLanguageResultExecution timeMemory
152991junodeveloperUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
5 ms556 KiB
#include <vector> #include <string> #include "messy.h" using namespace std; typedef vector<int> VI; int N; int p[128]; string Init() { string r=""; int i; for(i=0;i<N;i++) r+="0"; return r; } void Add(int l,int r) { if(l==r) return; int mid=(l+r)/2; Add(l,mid); Add(mid+1,r); int i; string s=Init(); for(i=l;i<=r;i++) s[i]='1'; for(i=l;i<=mid;i++) { s[i]='0'; add_element(s); s[i]='1'; } } void Solve(string a,int l,int r) { int i; if(l==r) { for(i=0;i<N;i++) if(a[i]=='1') { p[i]=l; break; } return; } string b=Init(); for(i=0;i<N;i++) { if(a[i]=='1') { a[i]='0'; if(check_element(a)) b[i]='1'; a[i]='1'; } } int mid=(l+r)/2; Solve(b,l,mid); for(i=0;i<N;i++) { if(a[i]=='1') b[i]=b[i]=='1'?'0':'1'; } Solve(b,mid+1,r); } std::vector<int> restore_permutation(int n, int w, int r) { N=n; int i; Add(0,N-1); compile_set(); string a=Init(); for(i=0;i<N;i++) a[i]='1'; Solve(a,0,N-1); vector<int> ret; for(i=0;i<N;i++) ret.push_back(p[i]); return ret; }
#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...