This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of Allah
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = (1 << 7) + 4;
int n; string s;
bool M[maxn]; int res[maxn];
vector<int> ans;
void addx() {
s = "";
for (int i = 0; i < n; i++) {
if (M[i]) s += "1";
else s += "0";
}
add_element(s);
}
bool checkx() {
s = "";
for (int i = 0; i < n; i++) {
if (M[i]) s += "1";
else s += "0";
}
return check_element(s);
}
void add_valx(int l, int r) {
if (r - l == 1) return ;
int mid = (l + r) / 2;
for (int i = mid; i < r; i++) {
M[i] = 1; addx(); M[i] = 0;
}
for (int i = mid; i < r; i++) M[i] = 1;
add_valx(l, mid);
for (int i = mid; i < r; i++) M[i] = 0;
for (int i = l; i < mid; i++) M[i] = 1;
add_valx(mid, r);
for (int i = l; i < mid; i++) M[i] = 0;
}
void get_valx(int l, int r, vector<int> ls) {
if (r - l == 1) {
res[ls[0]] = l;
return ;
}
int mid = (l + r) / 2;
vector<int> ls0, ls1;
for (int i : ls) {
M[i] = 1;
if (!checkx()) ls0.pb(i);
else ls1.pb(i);
M[i] = 0;
}
for (int i : ls1) M[i] = 1;
get_valx(l, mid, ls0);
for (int i : ls1) M[i] = 0;
for (int i : ls0) M[i] = 1;
get_valx(mid, r, ls1);
for (int i : ls0) M[i] = 0;
}
vector<int> restore_permutation(int N, int w, int r) {
n = N; add_valx(0, n);
compile_set();
vector<int> ls;
for (int i = 0; i < n; i++) ls.pb(i);
get_valx(0, n, ls);
ans.clear();
for (int i = 0; i < n; i++) ans.pb(res[i]);
return ans;
}
# | 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... |