이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define INF 2e18
#include "messy.h"
void add_element_connector(string &s){
add_element(s);
// cout << "Add: " << s << endl;
}
bool check_element_connector(string &s){
bool res=check_element(s);
// cout << "Check: " << s << ": " << res << endl;
return res;
}
void gen(ll l, ll r, ll n){
if (l>=r) return;
string s = ""; for (ll i=0; i<n; i++) s+="1";
for (ll i=l; i<=r; i++) s[i]='0';
ll mid = (l+r)/2;
for (ll i=l; i<=mid; i++){
s[i]='1';
add_element_connector(s);
s[i]='0';
}
gen(l, mid, n); gen(mid+1, r, n);
}
void restore(ll l, ll r, ll n, vector<ll> mem, vector<int> &perm){
if (l==r){
perm[mem[0]]=l;
return;
}
string s = "";
for (ll i=0; i<n; i++) s+='1';
for (auto i:mem) s[i]='0';
vector<ll> lmem, rmem;
for (auto i:mem){
s[i]='1';
if (check_element_connector(s)) lmem.push_back(i);
else rmem.push_back(i);
s[i]='0';
}
ll mid = (l+r)/2;
restore(l, mid, n, lmem, perm);
restore(mid+1, r, n, rmem, perm);
}
std::vector<int> restore_permutation(int n, int w, int r) {
gen(0, n-1, n);
compile_set();
vector<int> perm(n);
vector<ll> mem; for (ll i=0; i<n; i++) mem.push_back(i);
restore(0, n-1, n, mem, perm);
return perm;
}
# | 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... |