이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*input
*/
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
using bt = bitset<128>;
int N;
void add(bt b) {
str s = b.to_string();
reverse(s.begin(), s.end());
s.resize(N);
// cout << "add: " << s << '\n';
add_element(s);
}
bool check(bt b) {
str s = b.to_string();
reverse(s.begin(), s.end());
s.resize(N);
bool ans = check_element(s);
// cout << "check: " << s << " ans: " << (ans ? "true" : "false" ) << '\n';
return ans;
}
str print(bt b) {
str s = b.to_string();
reverse(s.begin(), s.end());
s.resize(N);
return s;
}
void add_all(bt space, int k) {
// cout << space.to_string() << " " << k << '\n';
if (k == 1) return;
bt curr = ~space;
int pr = k;
k /= 2;
bt left, right;
for (int i = 0; i < N; ++i)
{
if (space[i] and k) {
curr[i] = 1;
add(curr);
curr[i] = 0;
k--;
left[i] = 1;
} else if(space[i] and !k) {
right[i] = 1;
}
}
// cout << "left: " << print(left) << " right: " << print(right) << '\n';
add_all(left, pr / 2);
add_all(right, pr / 2);
}
vi P;
void finish(bt space, int k, bt kur) {
// cout << "space: " << print(space) << " k = " << k << " kur: " << print(kur) << '\n';
if (k == 1) {
int i = 0;
while (!space[i]) i++;
int j = 0;
while (!kur[j]) j++;
// printf("i = %d, j = %d\n", i, j);
// P[i] = j;
P[j] = i;
return;
}
bt curr = ~kur;
bt leftKur;
bt rightKur;
int pr = k;
k /= 2;
for (int i = 0; i < N; ++i)
{
if (kur[i]) {
curr[i] = 1;
if (check(curr)) {
leftKur[i] = 1;
// leftKur |= (curr & kur);
} else {
rightKur[i] = 1;
// rightKur |= (curr & kur);
}
curr[i] = 0;
}
}
bt left, right;
for (int i = 0; i < N; ++i)
{
if (space[i] and k) {
left[i] = 1;
k--;
} else if(space[i] and !k){
right[i] = 1;
}
}
finish(left, pr / 2, leftKur);
finish(right, pr / 2, rightKur);
}
std::vector<int> restore_permutation(int n, int w, int r) {
N = n;
bt curr;
curr.set();
add_all(curr, N);
compile_set();
P = vi(N);
finish(curr, N, curr);
return P;
}
# | 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... |