# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
917501 | oblantis | Unscrambling a Messy Bug (IOI16_messy) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e5 + 2;
#include "messy.h"
//namespace helper {
//set<string> set_;
//bool compiled = false;
//int n;
//vector<int> p;
//int w;
//int r;
//int read_int() {
//int x;
//cin >> x;
//return x;
//}
//}
//using namespace helper;
//void wa() {
//printf("WA\n");
//exit(0);
//}
//// A convenience function.
//int get_p(int i) {
//int ret = p[i];
//return ret;
//}
//bool check(const string& x) {
//if ((int)x.length() != n) {
//return false;
//}
//for (int i = 0; i < n; i++) {
//if (x[i] != '0' && x[i] != '1') {
//return false;
//}
//}
//return true;
//}
//void add_element(string x) {
//if (--w < 0 || compiled || !check(x)) {
//wa();
//}
//set_.insert(x);
//}
//bool check_element(string x) {
//if (--r < 0 || !compiled || !check(x)) {
//wa();
//}
//return set_.count(x);
//}
//void compile_set() {
//if (compiled) {
//wa();
//}
//compiled = true;
//set<string> compiledSet;
//string compiledElement = string(n, ' ');
//for (set<string>::iterator it = set_.begin(); it != set_.end(); it++) {
//string s = *it;
//for (int i = 0; i < n; i++) {
//compiledElement[i] = s[get_p(i)];
//}
//compiledSet.insert(compiledElement);
//}
//set_ = compiledSet;
}
void go(int l, int r, string s){
if(l + 1 == r)return;
int mid = (l + r) / 2;
for(int i = l; i < mid; i++){
s[i] = '1';
add_element(s);
s[i] = '0';
}
s.replace(l, (r - l) / 2, string((r - l) / 2, '1'));
go(mid, r, s);
s.replace(l, (r - l) / 2, string((r - l) / 2, '0'));
s.replace(mid, (r - l) / 2, string((r - l) / 2, '1'));
go(l, mid, s);
}
void fnd(vt<int> &ans, string s, int l, int r){
if(l + 1 == r){
for(int i = 0; i < (int)s.size(); i++){
if(s[i] == '0')ans[i] = l;
}
return;
}
vt<int> a, b;
for(int i = 0; i < (int)s.size(); i++){
if(s[i] == '0'){
s[i] = '1';
bool ok = check_element(s);
if(ok){
a.pb(i);
}
else b.pb(i);
s[i] = '0';
}
}
for(auto i : b){
s[i] = '1';
}
fnd(ans, s, l, (l + r) / 2);
for(auto i : b){
s[i] = '0';
}
for(auto i : a)s[i] = '1';
fnd(ans, s, (l + r) / 2, r);
}
vector<int> restore_permutation(int n, int w, int r) {
vt<int> ans(n, 0);
string s = string(n, '0');
go(0, n, s);
compile_set();
fnd(ans, string(n, '0'), 0, n);
return ans;
}
//int main() {
//n = read_int();
//w = read_int();
//r = read_int();
//p = vector<int>(n);
//for (int i = 0; i < n; i++) {
//p[i] = read_int();
//}
//vector<int> answer = restore_permutation(n, w, r);
//if (answer.size() != n) {
//printf("WA\n");
//return 0;
//}
//printf("%d", answer[0]);
//for (int i = 1; i < n; i++) {
//printf(" %d", answer[i]);
//}
//printf("\n");
//return 0;
//}