# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
536909 | DJ035 | 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 "messy.h"
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>
#define MEM 222
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 1e17+7;
const ll MOD = 998244353;
ll gcd(ll a, ll b){
if(a%b) return gcd(b, a%b);
return b;
}
int N;
vector<int> ans;
void ins(int l, int r) {
if(r-l==1) return;
string s(N, '0');
int mid=l+r>>1;
for(int i=l; i<r; i++)
s[i] = '1';
for(int i=l; i<mid; i++) {
s[i] = '0';
add_element(s);
s[i] = '1';
}
ins(l, mid);
ins(mid, r);
}
void hwak(vector<int> a, int k) {
if(a.sz()==1) {
ans[a[0]] = k;
return;
}
vector<int> l, r;
string s(N,'0');
for(int i:a)
s[i] = '1';
for(int i:a) {
s[i] = '0';
if(check_element(s)) l.push_back(i);
else r.push_back(i);
s[i] = '1';
}
hwak(l, k);
hwak(r, k+r.size());
}
std::vector<int> restore_permutation(int n, int w, int r) {
vector<int> im;
ans.resize(n);
N = n;
ins(0, n);
compile_set();
for(int i=0; i<n; i++)
im.push_back(i);
hwak(im, 0);
return ans;
}