제출 #938833

#제출 시각아이디문제언어결과실행 시간메모리
938833AlcabelUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
1 ms856 KiB
#include <bits/stdc++.h> #include "messy.h" using namespace std; string query; void rec_build(int l, int r) { if (r - l <= 1) { return; } int m = l + (r - l) / 2; for (int i = m; i < r; ++i) { query[i] = '1'; add_element(query); query[i] = '0'; } for (int i = l; i < m; ++i) { query[i] = '1'; } rec_build(m, r); for (int i = l; i < m; ++i) { query[i] = '0'; } for (int i = m; i < r; ++i) { query[i] = '1'; } rec_build(l, m); for (int i = m; i < r; ++i) { query[i] = '0'; } } void rec_find(vector<int>& rest, int bit, vector<int>& p) { if ((int)rest.size() <= 1) { return; } /*cerr << "rest:\n"; for (const int& i : rest) { cerr << i << ' '; } cerr << "\nbit: " << bit << '\n';*/ assert(bit >= 0); vector<int> on, off; for (const int& i : rest) { query[i] = '1'; if (check_element(query)) { p[i] |= (1 << bit); on.emplace_back(i); } else { off.emplace_back(i); } query[i] = '0'; } for (const int& i : off) { query[i] = '1'; } rec_find(on, bit - 1, p); for (const int& i : off) { query[i] = '0'; } for (const int& i : on) { query[i] = '1'; } rec_find(off, bit - 1, p); for (const int& i : on) { query[i] = '0'; } } vector<int> restore_permutation(int n, int w, int r) { vector<int> p(n); query = string(n, '0'); rec_build(0, n); compile_set(); int lg = 0; while ((1 << lg) < n) { ++lg; } vector<int> rest(n); iota(rest.begin(), rest.end(), 0); rec_find(rest, lg - 1, p); 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...