Submission #421130

#TimeUsernameProblemLanguageResultExecution timeMemory
421130SundavarUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
3 ms464 KiB
#include <bits/stdc++.h> using namespace std; void add_element(string s); bool check_element(string s); void compile_set(); int N; void insert(int l, int r){ string s(N, '1'); for(int i = l; i < r; i++) s[i] = '0'; int m = (l+r)/2; for(int i = l; i < m; i++) s[i] = '1', add_element(s), s[i] = '0'; if(l != r-1) insert(l, m), insert(m, r); } vector<int> ans; void revert(int l, int r, vector<int>& poss){ if(l == r-1){ ans[poss[0]] = l; return; } string s(N, '1'); for(int& a : poss) s[a] = '0'; vector<int> lef, rig; for(int& a : poss){ s[a] = '1'; if(check_element(s)) lef.push_back(a); else rig.push_back(a); s[a] = '0'; } revert(l, (l+r)/2, lef), revert((l+r)/2, r, rig); } vector<int> restore_permutation(int n, int w, int r) { N = n; insert(0,n); compile_set(); ans.resize(n); vector<int> poss(n); for(int i = 0; i < n; i++) poss[i] = i; revert(0, n, poss); 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...