# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
298336 | Hideo | Unscrambling a Messy Bug (IOI16_messy) | C++11 | 4 ms | 384 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"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mk make_pair
#define fr first
#define sc second
#define pb push_back
#define vi vector < int >
#define pi pair < int, int >
const int N = 256;
int x[N], us[N], go[N], rv[N], sz;
vi ans;
vi restore_permutation(int n, int w, int r){
srand(time(NULL));
if (n == 128)
sz = 11;
else
sz = 4;
for (int i = 1; i <= n; i++)
x[i] = i;
random_shuffle(x + 1, x + n + 1);
for (int i = 1; i <= n; i++)
rv[x[i]] = i;
int cc = 0;
for (int i = 1; i <= n; i++){
if (i > (cc + 1) * sz)
cc++;
string s = "";
for (int j = 1; j <= n; j++){
if (x[j] <= cc * sz || x[j] == i)
s += '1';
else
s += '0';
}
add_element(s);
}
for (int j = 1; j <= n; j++){
string s = "";
if (j % sz == 1){
for (int i = 1; i <= n; i++){
if (x[i] <= j)
s += '0';
else
s += '1';
}
}
else {
for (int i = 1; i <= n; i++){
if (x[i] <= j)
s += '1';
else
s += '0';
}
}
add_element(s);
}
compile_set();
set < int > st;
for (int i = 1; i <= n; i++)
st.insert(i);
for (int i = 1; i <= n; i += sz){
int r = min(i + sz - 1, n);
set < int > cur;
for (int it : st){
if (cur.size() == sz)
break;
string s = "";
for (int m = 1; m <= n; m++){
if (us[m] || m == it)
s += '1';
else
s += '0';
}
if (check_element(s))
cur.insert(it);
}
for (int it : cur)
st.erase(it);
for (int j = i; j < r; j++){
int f = 0;
for (int it : cur){
if (it == *cur.rbegin()){
f = it;
break;
}
string s = "";
for (int m = 1; m <= n; m++){
if ((j == i && (us[m] || m == it)) || (j != i && !us[m] && m != it))
s += '0';
else
s += '1';
}
if (check_element(s)){
f = it;
break;
}
}
cur.erase(f);
us[f] = rv[j];
}
us[*cur.begin()] = rv[r];
cur.erase(*cur.begin());
}
for (int i = 1; i <= n; i++)
ans.pb(us[i] - 1);
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |