Submission #658243

#TimeUsernameProblemLanguageResultExecution timeMemory
658243benjaminkleynUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms468 KiB
#include <bits/stdc++.h> #include "messy.h" using namespace std; typedef long long ll; vector<int> res; void find(const int &l, const int &r, const vector<int> &idx, const int &n) { /* // debug cout << "(l, r) = (" << l << ", " << r << ")\n"; cout << "idx = ["; for (int x : idx) cout << x << " "; cout << "]\n"; */ if (l == r) { res[idx[0]] = l; return; } // assuming we know the indices in idx are mapped to the range [l, r] vector<int> left_idx, right_idx; for (const int &i : idx) { string s(n, '1'); for (const int &j : idx) if (j != i) s[j] = '0'; if (check_element(s)) left_idx.push_back(i); else right_idx.push_back(i); } find(l, (l + r) / 2, left_idx, n); find((l + r) / 2 + 1, r, right_idx, n); } vector<int> restore_permutation(int n, int w, int r) { // consider a number of the form // // 10000000 // 01000000 // 00100000 // 00010000 // // or something like that, so we can halve the searching space. string s; for (int k = 1; k < n; k *= 2) { // cout << k << '\n'; for (int i = 0; i < n; i += 2 * k) { s = string(n, '1'); for (int j = i; j < i + 2 * k; j++) s[j] = '0'; for (int j = i; j < i + k; j++) { s[j] = '1'; // cout << s << '\n'; add_element(s); s[j] = '0'; } } } compile_set(); vector<int> idx(n); iota(idx.begin(), idx.end(), 0); res.resize(n); find(0, n - 1, idx, n); return res; }
#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...