Submission #1021898

#TimeUsernameProblemLanguageResultExecution timeMemory
1021898vjudge1Unscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms856 KiB
#include <bits/stdc++.h> #define ent '\n' typedef long long ll; using namespace std; const int maxn = 2e5+12; void add_element(std::string x); bool check_element(std::string x); void compile_set(); int per[maxn]; void rec(vector<int> a, int b, int n){ if(a.size() == 1) return; vector<int> l, r; string s0 = ""; for(int i=0;i<n;i++){ bool ok = 0; for(int x:a){ if(x == i){ ok = 1; } } if(!ok){ s0 += '0'; } else{ s0 += '1'; } } for(int x:a){ if(!(x & (1 << b))){ s0[x] = '0'; add_element(s0); l.push_back(x); s0[x] = '1'; } else r.push_back(x); } rec(l, b-1, n); rec(r, b-1, n); } void find(vector<int> a, int b, int n, int val){ if(b < -1) return; if(a.size() == 1){ per[a[0]] = val; return; } vector<int> l, r; string s0 = ""; for(int i=0;i<n;i++){ bool ok = 0; for(int x:a){ if(x == i){ ok = 1; } } s0 += '0' + ok; } for(int x:a){ s0[x] = '0'; if(check_element(s0)){ l.push_back(x); } else{ r.push_back(x); } s0[x] = '1'; } find(l, b-1, n, val); find(r, b-1, n, val + (1 << b)); } std::vector<int> restore_permutation(int n, int w, int r){ vector<int> a; for(int i=0;i<n;i++){ a.push_back(i); } int b = 0; while((1 << (b + 1)) < n){ b++; } rec(a, b, n); compile_set(); find(a, b, n, 0); vector<int> ans(per, per+n); 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...