# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650364 | rafatoa | Unscrambling a Messy Bug (IOI16_messy) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#pragma GCC optimize ("Ofast")
#define double ld
const int inf = 2e9;
const int INF = 4e18;
const int mod = 1e9+7;
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";
#define rs resize
#define as assign
#define vc vector<char>
#define vvc vector<vc>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ppb pop_back
#define MP make_pair
// #define int ll
void add_element(string x);
void compile_set();
bool check_element(string x);
int[] restore_permutation(int n, int w, int r){
int p[n];
function<void(int, int)> add = [&](int l, int r){
if(l == r) return;
for(int j=l; j<l+(r-l+1)/2; j++){
string s;
for(int i=0; i<n; i++)
if(i < l || i > r || i == j) s += '1';
else s += '0';
add_element(s);
}
add(l, l+(r-l+1)/2-1);
add(l+(r-l+1)/2, r);
};
add(0, n-1);
compile_set();
function<void(int, int, vi)> solve = [&](int l, int r, vi v){
if(l == r){
p[n-1-l] = n-1-v[0];
return;
}
vi a, b;
for(auto &x:v){
string s;
for(int i=0; i<n; i++){
if(i != x && binary_search(all(v), i)) s += '0';
else s += '1';
}
if(check_element(s)) a.pb(x);
else b.pb(x);
}
solve(l, l+(r-l+1)/2-1, a);
solve(l+(r-l+1)/2, r, b);
};
vi v; iota(all(v), 0);
solve(0, n-1, v);
return p;
}
/*stolen stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* READ CONSTRAINTS
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/