Submission #765116

#TimeUsernameProblemLanguageResultExecution timeMemory
765116raysh07Unscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms476 KiB
#include "messy.h" #include <bits/stdc++.h> using namespace std; vector <int> p; int n; void build(int l, int r){ if (l == r) return; int m = (l + r)/2; string s; for (int i = 0; i < n; i++){ if (i >= l && i <= r) s += "0"; else s += "1"; } for (int i = l; i <= m; i++){ string st = s; st[i] = '1'; add_element(st); } build(l, m); build(m + 1, r); } void solve(int l, int r, vector<int> curr, vector<int> other){ if (l == r){ p[l] = curr[0]; return; } int m = (l + r)/2; string s; for (int i = 0; i < n; i++) s += "0"; for (auto x : other) s[x] = '1'; vector <int> n1, n2; for (auto x : curr){ string st = s; st[x] = '1'; if (check_element(st)){ n1.push_back(x); } else { n2.push_back(x); } } vector <int> o1 = other; for (auto x : n2) o1.push_back(x); solve(l, m, n1, o1); vector <int> o2 = other; for (auto x : n1) o2.push_back(x); solve(m + 1, r, n2, o2); } vector<int> restore_permutation(int m, int w, int r) { // add_element("0"); // compile_set(); // check_element("0"); // return std::vector<int>(); n = m; p.resize(n); build(0, n - 1); compile_set(); vector <int> curr; for (int i = 0; i < n; i++) curr.push_back(i); vector <int> other; solve(0, n - 1, curr, other); vector <int> inv(n); for (int i = 0; i < n; i++) inv[p[i]] = i; return inv; }
#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...