# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586149 | Tien_Noob | 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.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
//#include <messy.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
string s;
vector<int> res;
void gen(int l, int r)
{
if (l == r)
{
return ;
}
int mid = (l + r)/2;
for (int i = mid + 1; i <= r; ++ i)
{
s[i] = '0';
}
for (int i = l; i <= mid; ++ i)
{
s[i] = '0';
}
for (int i = l; i <= mid; ++ i)
{
s[i] = '1';
//cerr << s << '\n';
add_element(s);
s[i] = '0';
}
for (int i = mid + 1; i <= r; ++ i)
{
s[i] = '1';
}
gen(l, mid);
for (int i = l; i <= mid; ++ i)
{
s[i] = '0';
}
for (int i = mid + 1; i <= r; ++ i)
{
s[i] = '0';
}
for (int i = mid + 1; i <= r; ++ i)
{
s[i] = '1';
//cerr << s << '\n';
add_element(s);
s[i] = '0';
}
for (int i = l; i <= mid; ++ i)
{
s[i] = '1';
}
gen(mid + 1, r);
}
void DnC(int l, int r, vector<int> val)
{
if (l == r)
{
assert(!val.empty());
res[l] = val.front();
return ;
}
vector<int> L, R;
int mid = (l + r)/2;
for (int i : val)
{
s[i] = '0';
}
for (int i : val)
{
s[i] = '1';
if (check_element(s))
{
L.push_back(i);
}
else
{
R.push_back(i);
}
s[i] = '0';
}
for (int i : L)
{
s[i] = '0';
}
for (int i : R)
{
s[i] = '1';
}
DnC(l, mid, L);
for (int i : R)
{
s[i] = '0';
}
for (int i : L)
{
s[i] = '1';
}
DnC(mid + 1, r, R);
}
vector<int> restore_permutation(int n, int w, int r)
{
s.resize(n, '0');
res.resize(n);
gen(0, n - 1);
compile_set();
vector<int> tmp(n);
iota(tmp.begin(), tmp.end(), 0);
DnC(0, n - 1, tmp);
return res;
}
/*void read()
{
restore_permutation(8, 10, 10);
}
void solve()
{
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}*/