Submission #575848

#TimeUsernameProblemLanguageResultExecution timeMemory
575848lorenzoferrariUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms468 KiB
#include "messy.h" #include <set> #include <vector> #include <cassert> #include <numeric> #include <iostream> using namespace std; int n; vector<int> p; void fill_set(int l, int r) { if (l == r) return; 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'; } fill_set(l, m); fill_set(m+1, r); } void query_set(int l, int r, vector<int> pp) { assert(int(pp.size()) == r-l+1); if (l == r) { p[pp[0]] = l; return; } string s(n, '1'); for (int i = 0; i <= r-l; ++i) s[pp[i]] = '0'; vector<int> ppa, ppb; for (int i = 0; i <= r-l; ++i) { s[pp[i]] = '1'; if (check_element(s)) { ppa.push_back(pp[i]); } else { ppb.push_back(pp[i]); } s[pp[i]] = '0'; } int m = (l + r) / 2; query_set(l, m, ppa); query_set(m+1, r, ppb); } vector<int> restore_permutation(int n, int w, int r) { ::n = n; p.resize(n); fill_set(0, n-1); compile_set(); vector<int> pp(n); iota(pp.begin(), pp.end(), 0); query_set(0, n-1, pp); return p; }
#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...