이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "messy.h"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 205
int n;
vector<int> p;
vector<int> ans;
void add(int l,int r){
if(l==r) return;
//cerr<<l<< " "<<r<<endl;
string s(n,'0');
int mid = (l+r)/2;
for(int i = 0;i<l;i++) s[i] = '1';
for(int i = r+1;i<n;i++) s[i] = '1';
for(int i = l;i<=mid;i++){
s[i] = '1';
add_element(s);
//cerr<<s<<endl;
s[i] = '0';
}
add(l,mid);
add(mid+1,r);
}
void reshi(int l,int r){
if(r==l) return;
string s(n,'0');
int mid = (l+r)/2;
for(int i = 0;i<l;i++) s[p[i]] = '1';
for(int i = r+1;i<n;i++) s[p[i]] = '1';
vector<int> ls,rs;
//here;
for(int i = l;i<=r;i++){
s[p[i]] = '1';
bool ima = check_element(s);
//cerr<<s<< " "<<ima<<endl;
if(ima) ls.pb(p[i]);
else rs.pb(p[i]);
s[p[i]] = '0';
}
for(int i = l;i<=mid;i++) p[i] = ls[i-l];
for(int i = mid+1;i<=r;i++) p[i] = rs[i-mid-1];
/*
cerr<<l<< " "<<r<<endl;
for(ll x : ls) cerr<<x<< " ";
cerr<<endl;
for(ll x : rs) cerr<<x<< " ";
cerr<<endl;
*/
reshi(l,mid);
reshi(mid+1,r);
}
vector<int> restore_permutation(int N, int w, int r) {
n = N;
p.resize(n);
iota(all(p),0);
add(0,n-1);
compile_set();
reshi(0,n-1);
ans.resize(n);
for(ll i = 0;i<n;i++) ans[p[i]] = i;
return ans;
}
/*
4 16 16
2 1 3 0
*/
# | 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... |