Submission #568105

#TimeUsernameProblemLanguageResultExecution timeMemory
568105ngpin04Unscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
3 ms484 KiB
#include "messy.h" #include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "" #define bit(x) (1LL << (x)) #define getbit(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rd() % (r - l + 1); } const int N = 1e5 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); #define add add_element #define done compile_set #define ask check_element string s; int ans[N]; int f[N]; int ____n; void build(int l, int r) { if (l == r) return; int mid = (l + r) >> 1; for (int i = l; i <= r; i++) s[i] = '0'; for (int i = l; i <= mid; i++) { s[i] = '1'; add(s); // cerr << "add " << s << "\n"; s[i] = '0'; } for (int i = mid + 1; i <= r; i++) s[i] = '1'; build(l, mid); for (int i = l; i <= mid; i++) s[i] = '1'; build(mid + 1, r); } void getans(int l, int r) { int mid = (l + r) >> 1; vector <int> setl, setr; for (int i = 0; i < ____n; i++) if (s[i] != '1') { s[i] = '1'; if (ask(s)) setl.push_back(i); else setr.push_back(i); // cerr << "ask " << i << " " << s << "\n"; s[i] = '0'; } // for (int x : setl) // cerr << x << " "; // cerr << "\n"; if (setl.size() == 1 && setr.size() == 1) { ans[l] = *setl.begin(); ans[r] = *setr.begin(); return; } for (int i : setr) s[i] = '1'; getans(l, mid); for (int i : setr) s[i] = '0'; for (int i : setl) s[i] = '1'; getans(mid + 1, r); for (int i : setl) s[i] = '0'; } void solve() { s.resize(____n); build(0, ____n - 1); done(); s.assign(____n, '0'); getans(0, ____n - 1); } vector<int> restore_permutation(int _n, int w, int r) { ____n = _n; solve(); vector <int> res; for (int i = 0; i < ____n; i++) f[ans[i]] = i; for (int i = 0; i < ____n; i++) res.push_back(f[i]); return res; } //#include "grader.cpp"
#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...