#include <bits/stdc++.h>
#include "messy.h"
#define vc vector
using namespace std;
/*string permute(string s, vc<int> p){
cout << s << endl;
assert(s.size()==p.size());
string ret(s.size(), '.');
for(int i=0;i<s.size();++i) ret[i]=s[p[i]];
return ret;
}
int cw=0, cr=0;
set<string> notr;
bool check_element(string s){
++cr;
cout << s << endl;
return notr.count(s)>0;
}
vc<int> p;
void add_element(string s){
++cw;
cout << s << endl;
notr.insert(permute(s, p));
}
void compile_set(){cout << '\n';}*/
/////////
void badd(int l, int r, int n){
if(l+1==r) return;
int mid=(l+r)/2;
string s(n, '1');
for(int i=l; i<r;++i) s[i]='0';
for(int i=l; i<mid;++i){
string t=s;
t[i]='1';
add_element(t);
}
badd(l, mid, n);
badd(mid, r, n);
}
void bquery(int l, int r, int n, vc<int>& ans){
if(l+1==r) return;
int mid=(l+r)/2;
string s(n, '1');
for(int i=l; i<r;++i) s[ans[i]]='0';
set<int> ls, rs;
for(int i=l; i<r;++i){
string t=s;
t[ans[i]]='1';
if(check_element(t)) ls.insert(ans[i]);
else rs.insert(ans[i]);
}
vc<int> lv(ls.begin(), ls.end()), rv(rs.begin(), rs.end());
assert(lv.size()==(mid-l) and rv.size()==(r-mid));
for(int i=l;i<mid;++i) ans[i]=lv[i-l];
for(int i=mid;i<r;++i) ans[i]=rv[i-mid];
bquery(l, mid, n, ans);
bquery(mid, r, n, ans);
}
vc<int> inv(vc<int> ans){
vc<int> ret(ans.size());
for(int i=0;i<ans.size();++i) ret[ans[i]]=i;
return ret;
}
vc<int> restore_permutation(int n, int w, int r){
badd(0, n, n);
compile_set();
vc<int> ans(n); for(int i=0;i<n;++i) ans[i]=i;
bquery(0, n, n, ans);
return inv(ans);
}
/*int main(){
int n=4;
p={2, 1, 3, 0};
vc<int> ans= restore_permutation(n, 0, 0);
for(int i=0;i<n;++i) cout << ans[i]<<" ";cout << '\n';
cout << cw << " "<< cr << endl;
}*/
Compilation message
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from messy.cpp:1:
messy.cpp: In function 'void bquery(int, int, int, std::vector<int>&)':
messy.cpp:66:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | assert(lv.size()==(mid-l) and rv.size()==(r-mid));
| ~~~~~~~~~^~~~~~~~~
messy.cpp:66:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | assert(lv.size()==(mid-l) and rv.size()==(r-mid));
| ~~~~~~~~~^~~~~~~~~
messy.cpp: In function 'std::vector<int> inv(std::vector<int>)':
messy.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i=0;i<ans.size();++i) ret[ans[i]]=i;
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 8 |
2 |
Correct |
1 ms |
212 KB |
n = 8 |
3 |
Correct |
1 ms |
212 KB |
n = 8 |
4 |
Correct |
1 ms |
212 KB |
n = 8 |
5 |
Correct |
1 ms |
212 KB |
n = 8 |
6 |
Correct |
0 ms |
212 KB |
n = 8 |
7 |
Correct |
1 ms |
212 KB |
n = 8 |
8 |
Correct |
0 ms |
212 KB |
n = 8 |
9 |
Correct |
1 ms |
212 KB |
n = 8 |
10 |
Correct |
1 ms |
296 KB |
n = 8 |
11 |
Correct |
1 ms |
212 KB |
n = 8 |
12 |
Correct |
1 ms |
300 KB |
n = 8 |
13 |
Correct |
1 ms |
212 KB |
n = 8 |
14 |
Correct |
1 ms |
212 KB |
n = 8 |
15 |
Correct |
1 ms |
212 KB |
n = 8 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 32 |
2 |
Correct |
1 ms |
212 KB |
n = 32 |
3 |
Correct |
1 ms |
212 KB |
n = 32 |
4 |
Correct |
1 ms |
212 KB |
n = 32 |
5 |
Correct |
1 ms |
212 KB |
n = 32 |
6 |
Correct |
1 ms |
212 KB |
n = 32 |
7 |
Correct |
1 ms |
212 KB |
n = 32 |
8 |
Correct |
1 ms |
212 KB |
n = 32 |
9 |
Correct |
1 ms |
212 KB |
n = 32 |
10 |
Correct |
1 ms |
304 KB |
n = 32 |
11 |
Correct |
1 ms |
212 KB |
n = 32 |
12 |
Correct |
1 ms |
304 KB |
n = 32 |
13 |
Correct |
1 ms |
292 KB |
n = 32 |
14 |
Correct |
1 ms |
340 KB |
n = 32 |
15 |
Correct |
1 ms |
296 KB |
n = 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 32 |
2 |
Correct |
1 ms |
212 KB |
n = 32 |
3 |
Correct |
1 ms |
212 KB |
n = 32 |
4 |
Correct |
1 ms |
212 KB |
n = 32 |
5 |
Correct |
1 ms |
304 KB |
n = 32 |
6 |
Correct |
1 ms |
212 KB |
n = 32 |
7 |
Correct |
1 ms |
212 KB |
n = 32 |
8 |
Correct |
1 ms |
212 KB |
n = 32 |
9 |
Correct |
1 ms |
212 KB |
n = 32 |
10 |
Correct |
1 ms |
212 KB |
n = 32 |
11 |
Correct |
1 ms |
212 KB |
n = 32 |
12 |
Correct |
0 ms |
212 KB |
n = 32 |
13 |
Correct |
1 ms |
212 KB |
n = 32 |
14 |
Correct |
1 ms |
212 KB |
n = 32 |
15 |
Correct |
1 ms |
212 KB |
n = 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
n = 128 |
2 |
Correct |
1 ms |
468 KB |
n = 128 |
3 |
Correct |
2 ms |
468 KB |
n = 128 |
4 |
Correct |
2 ms |
432 KB |
n = 128 |
5 |
Correct |
2 ms |
468 KB |
n = 128 |
6 |
Correct |
2 ms |
468 KB |
n = 128 |
7 |
Correct |
2 ms |
468 KB |
n = 128 |
8 |
Correct |
2 ms |
468 KB |
n = 128 |
9 |
Correct |
1 ms |
468 KB |
n = 128 |
10 |
Correct |
1 ms |
432 KB |
n = 128 |
11 |
Correct |
1 ms |
424 KB |
n = 128 |
12 |
Correct |
2 ms |
428 KB |
n = 128 |
13 |
Correct |
2 ms |
468 KB |
n = 128 |
14 |
Correct |
1 ms |
468 KB |
n = 128 |
15 |
Correct |
1 ms |
424 KB |
n = 128 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
n = 128 |
2 |
Correct |
1 ms |
468 KB |
n = 128 |
3 |
Correct |
1 ms |
468 KB |
n = 128 |
4 |
Correct |
1 ms |
468 KB |
n = 128 |
5 |
Correct |
1 ms |
468 KB |
n = 128 |
6 |
Correct |
5 ms |
468 KB |
n = 128 |
7 |
Correct |
2 ms |
416 KB |
n = 128 |
8 |
Correct |
2 ms |
468 KB |
n = 128 |
9 |
Correct |
2 ms |
428 KB |
n = 128 |
10 |
Correct |
1 ms |
468 KB |
n = 128 |
11 |
Correct |
2 ms |
468 KB |
n = 128 |
12 |
Correct |
2 ms |
468 KB |
n = 128 |
13 |
Correct |
2 ms |
468 KB |
n = 128 |
14 |
Correct |
2 ms |
468 KB |
n = 128 |
15 |
Correct |
1 ms |
428 KB |
n = 128 |