이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "messy.h"
string inv(string s) {
if (s == "W") return s;
for (char& ch : s) ch = '1' - ch + '0';
return s;
}
vector<string> dirs;
int n;
void ranges(int L, int R, string t) {
if (R-L+1 == 1) return;
/*cout << "RANGE: " << L+1 << " " << R+1 << endl;*/
int M = (L + R) / 2;
if (t == "W") {
string s(n, '1');
replr(i, L, R) s[i] = '0';
int cnt = 0;
replr(i, 0, n-1) if (cnt < (R-L+1)/2 && s[i] == '0') {
s[i] = '1';
add_element(s);
s[i] = '0';
cnt++;
}
ranges(M+1, R, t);
ranges(L, M, t);
} else {
string s = t;
replr(i, 0, n-1) if (t[i] == '0') {
s[i] = '1';
if (check_element(s)) {
t[i] = '1';
}
s[i] = '0';
}
/*cout << t << endl;*/
rep(i, n) if (s[i] == '0') {
if (t[i] == '1') {
dirs[i].pb('L');
} else {
dirs[i].pb('R');
}
}
ranges(M+1, R, t);
rep(i, n) if (s[i] == '0') t[i] = '1' - t[i] + '0';
ranges(L, M, t);
}
}
int getnum(string s) {
int l = 0;
int r = n-1;
for (char ch : s) {
int m = (l+r)/2;
if (ch == 'L') r = m;
else l = m+1;
}
return l;
}
VI restore_permutation(int N, int w, int r) {n = N;
ranges(0, n-1, "W");
compile_set();
dirs = vector<string>(n);
ranges(0, n-1, string(n, '0'));
VI ret;
for (string s : dirs) {
ret.pb(getnum(s));
/*cout << getnum(s) << " "; cout << endl;*/
}
return ret;
}
# | 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... |