Submission #405371

#TimeUsernameProblemLanguageResultExecution timeMemory
405371rocks03Unscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
3 ms556 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define pb push_back #define SZ(x) ((int)(x).size()) #define all(x) x.begin(), x.end() #define debug(x) cout << #x << ": " << x << " " #define nl cout << "\n" #define rep(i, a, b) for(int i = (a); i <= (b); i++) #define per(i, a, b) for(int i = (a); i >= (b); i--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void add_element(string x); void compile_set(); bool check_element(string x); vector<string> elementi; void prepara(int l, int r, string& s){ if(l == r) return; int m = (l + r) / 2; rep(i, l, m){ s[i] = '1'; elementi.pb(s); s[i] = '0'; } rep(i, m + 1, r) s[i] = '1'; prepara(l, m, s); rep(i, m + 1, r) s[i] = '0'; rep(i, l, m) s[i] = '1'; prepara(m + 1, r, s); rep(i, l, m) s[i] = '0'; } vector<int> ans; void solve(int l, int r, vector<int>& q, string& s){ if(l == r){ assert(SZ(q) == 1); ans[q[0]] = l; return; } int m = (l + r) / 2; vector<int> ql, qr; string sl = s, sr = s; for(int i : q){ s[i] = '1'; if(check_element(s)){ ql.pb(i); sr[i] = '1'; } else{ qr.pb(i); sl[i] = '1'; } s[i] = '0'; } solve(l, m, ql, sl); solve(m + 1, r, qr, sr); } vector<int> restore_permutation(int N, int W, int R){ string s(N, '0'); prepara(0, N - 1, s); for(string x : elementi) add_element(x); compile_set(); ans = vector<int>(N); vector<int> q(N); iota(all(q), 0); solve(0, N - 1, q, s); return ans; }
#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...