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 <vector>
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 130
#include "messy.h"
int N, P[MAXN], Q[MAXN];
void update(int l, int r) {
if(l == r) return;
string s = string(N, '0');
for(int i = 1; i < l; i++) s[i-1] = '1';
for(int i = N; i > r; i--) s[i-1] = '1';
for(int i = l; i <= mid; i++) {
s[i-1] = '1';
add_element(s);
s[i-1] = '0';
}
update(l, mid); update(mid+1, r);
}
vector<int> p, d;
void query(int l, int r) {
if(l == r) return;
p.clear(); d.clear();
string s = string(N, '0');
for(int i = 1; i < l; i++) s[P[i]] = '1';
for(int i = N; i > r; i--) s[P[i]] = '1';
for(int i = l; i <= r; i++) {
s[P[i]] = '1';
if(check_element(s)) p.pb(P[i]);
else d.pb(P[i]);
s[P[i]] = '0';
}
for(int i = l; i <= r; i++) {
if(!p.empty()) P[i] = p.back(), p.pop_back();
else P[i] = d.back(), d.pop_back();
}
query(l, mid); query(mid+1, r);
}
std::vector<int> restore_permutation(int n, int w, int r) {
N = n;
update(1, N);
compile_set();
for(int i = 1; i <= N; i++) P[i] = i-1;
query(1, N);
vector<int> rez;
for(int i = 0; i < N; i++) {
for(int j = 1; j <= N; j++) {
if(P[j] == i) rez.pb(j-1);
}
}
return rez;
}
# | 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... |