이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <bit>
#include <string>
#include "messy.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef vector<vll> vvll;
typedef bitset<128> bits;
typedef vector<bits> vbits;
typedef set<bits> sbits;
typedef vector<bool> vb;
typedef pair<bits, bool> pbits_b;
typedef vector<pbits_b> vpbits_b;
const ll TWO[8] = {1, 2, 4, 8, 16, 32, 64, 128};
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define sz(a) (ll) a.size()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define trav(i, a, t) for (t::iterator i = a.begin(); i != a.end(); i++)
ll n, w, r;
ll b;
void add_elements(ll l, ll r) {
if (l == r) return;
// add elements with all outside [l, r] 1s, and first half of [l, r] containing one 1
string s;
rep(i, 0, l) s += '1';
rep(i, l, r + 1) s += '0';
rep(i, r + 1, n) s += '1';
ll m = (l + r) / 2;
rep(i, l, m + 1) {
s[i] = '1';
//cout << "added: " << s << endl;
add_element(s);
s[i] = '0';
}
add_elements(l, m);
add_elements(m + 1, r);
}
vvll p;
std::vector<int> p_answ;
void check_elements(ll d, ll l, ll r, string& s) {
if (l == r) {
p_answ[p[d][l]] = l;
return;
}
//cout << "check_elements(" << d << ", " << l << ", " << r << ") s: " << s << endl;
// check how elements created by add_elements(l, r) have been displaced
// the passed in string contains 1's where elements [0, l)U(r, n - 1] have been displaced
// p[l:r] contains the set of indices to which [l, r] is displaced
ll m = (l + r) / 2;
// here we find p[l:m] and p[m+1:r]
vll lm;
vll mr;
rep(i, l, r + 1) {
s[p[d][i]] = '1';
//cout << "check_element: " << s << " -> ";
if (check_element(s)) {
//cout << "true" << endl;
lm.pb(p[d][i]);
} else {
//cout << "false" << endl;
mr.pb(p[d][i]);
}
s[p[d][i]] = '0';
}
/* cout << "lm " << sz(lm) << " & mr " << sz(mr) << " s: " << s << endl;
cout << "lm: ";
trav(itr, lm, vll) {
cout << *itr << " ";
}
cout << endl;
cout << "mr: ";
trav(itr, mr, vll) {
cout << *itr << " ";
}
cout << endl; */
rep(i, l, m + 1) {
p[d + 1][i] = lm[i - l];
}
rep(i, m + 1, r + 1) {
p[d + 1][i] = mr[i - (m + 1)];
}
// iterate downward
rep(i, m + 1, r + 1) s[p[d + 1][i]] = '1';
check_elements(d + 1, l, m, s);
rep(i, m + 1, r + 1) s[p[d + 1][i]] = '0';
rep(i, l, m + 1) s[p[d + 1][i]] = '1';
check_elements(d + 1, m + 1, r, s);
rep(i, l, m + 1) s[p[d + 1][i]] = '0';
}
std::vector<int> restore_permutation(int n_, int w_, int r_) {
n = n_; w = w_; r = r_;
// determine b
b = 0; while (n ^ TWO[b]) b++;
//cout << "add_elements" << endl;
add_elements(0, n - 1);
//cout << "compile_set" << endl;
compile_set();
//cout << "setup check_elements" << endl;
p_answ.resize(n);
p.resize(b + 1);
rep(i, 0, b + 1) p[i].resize(n);
rep(i, 0, n) p[0][i] = i;
string s;
rep(i, 0, n) s += "0";
//cout << "check_elements" << endl;
check_elements(0, 0, n - 1, s);
return p_answ;
}
# | 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... |