이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifndef wambule
#include "messy.h"
#else
set<string> se;
vector<int> p;
bool mbo;
void add_element(string s) {
if(!mbo) se.clear();
mbo = 1;
// cout << "[+] " << s << endl;
se.insert(s);
}
void compile_set() {
mbo = 0;
vector<string> v;
for(auto it = se.begin(); it != se.end(); ++it) {
string t = *it;
for(int i = 0; i < t.size(); ++i) {
t[i] = (*it)[p[i]];
}
v.push_back(t);
}
se.clear();
for(int i = 0; i < v.size(); ++i) {
se.insert(v[i]);
}
}
bool check_element(string s) {
// cout << "[??] " << s << " - " << (se.find(s) != se.end()) << endl;
return (se.find(s) != se.end());
}
void P(vector<int> v) {
for(int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << endl;
}
#endif
string O(int n) {
string s = "";
for(int i = 0; i < n; ++i) {
s += '0';
}
return s;
}
vector<int> I(vector<int> v) {
vector<int> dr(v.size());
for(int i = 0; i < v.size(); ++i) {
dr[v[i]] = i;
}
return dr;
}
string s;
vector<int> dr, rd;
inline int M(int l, int r) {
return (l + r) / 2;
}
void A(int l, int r) {
if(r - l <= 2) return;
int m = M(l, r);
for(int i = l; i < m; ++i) s[i] = '1';
for(int i = m; i < M(m, r); ++i) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
for(int i = l; i < m; ++i) s[i] = '0';
///
for(int i = m; i < r; ++i) s[i] = '1';
for(int i = l; i < M(l, m); ++i) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
for(int i = m; i < r; ++i) s[i] = '0';
A(l, m);
A(m, r);
}
void C(int l, int r) {
if(r - l <= 2) return;
// cout << "[SGSG] " << l << " " << r << endl;
int m = M(l, r), x = m;
for(int i = l; i < m; ++i) s[rd[i]] = '1';
for(int i = m; i < r; ++i) {
int y;
s[y = rd[i]] = '1';
if(check_element(s)) {
swap(rd[i], rd[x]); ++x;
}
s[y] = '0';
}
for(int i = l; i < m; ++i) s[rd[i]] = '0';
x = l;
for(int i = m; i < r; ++i) s[rd[i]] = '1';
for(int i = l; i < m; ++i) {
int y;
s[y = rd[i]] = '1';
if(check_element(s)) {
swap(rd[i], rd[x]); ++x;
}
s[y] = '0';
}
for(int i = m; i < r; ++i) s[rd[i]] = '0';
// P(rd);
C(l, m);
C(m, r);
}
vector<int> restore_permutation(int n, int = 0, int = 0) {
dr.resize(n);
s = O(n);
rd.resize(n);
for(int i = 0; i < M(0, n); ++i) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
A(0, n);
compile_set();
int x = 0, y = M(0, n);
for(int i = 0; i < n; ++i) {
s[i] = '1';
if(check_element(s)) {
rd[x++] = i;
} else {
rd[y++] = i;
}
s[i] = '0';
}
// P(rd);
C(0, n);
dr = I(rd);
return dr;
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
do {
int n = 128;
p.clear();
for(int i = 0; i < n; ++i) p.push_back(i);
random_shuffle(p.begin(), p.end());
// p = {4, 7, 3, 2, 6, 5, 1, 0}; n = p.size();
P(p);
p = I(p);
P(p);
p = I(p);
vector<int> v = restore_permutation(n);
cout << "[=] " << (v == p) << endl;
P(v);
v = I(v); P(v);
p = I(p); P(p);
cout << endl << "____________________" << endl << endl;
if(v != p) cin.get();
} while(1);
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
messy.cpp: In function 'std::vector<int> I(std::vector<int>)':
messy.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
# | 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... |