#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void add_element(string x);
bool check_element(string x);
void compile_set();
vector<int> bf(int n) {
mt19937 cowng(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 1; i <= n; i++) {
add_element(string(i, '1') + string(n - i, '0'));
}
compile_set();
string cur(n, '0');
vector<int> ans;
for (int i = 0; i < n; i++) {
vector<int> left;
bool vis[n] {};
for (auto& a : ans) {
vis[a] = true;
}
for (int j = 0; j < n; j++) {
if (!vis[j]) {
left.push_back(j);
}
}
shuffle(begin(left), end(left), cowng);
for (auto& a : left) {
cur[a] = '1';
if (check_element(cur)) {
ans.push_back(a);
break;
}
cur[a] = '0';
}
}
vector<int> tmp(n);
for (int i = 0; i < n; i++) {
tmp[ans[i]] = i;
}
return tmp;
}
vector<int> restore_permutation(int n, int, int) {
if (n <= 8) {
return bf(n);
}
for (int i = 0; i < 8; i++) {
string s(n, '1');
s[i] = '0';
add_element(s);
}
int acnts[8] {};
for (int i = 7; i >= 0; i--) {
if (i & 1) {
for (int j = i + 1; j < 8; j++) {
acnts[i]++;
acnts[j]++;
string s(n, '1');
s[i] = s[j] = '0';
add_element(s);
}
}
}
assert(acnts[6] == acnts[7]);
for (int i = 0; i < 7; i++) {
for (int j = 6; j < n; j++) {
if ((j >> i) & 1) {
string s(n, '0');
s[j] = '1';
for (int k = 0; k < i; k++) {
s[k] = '1';
}
add_element(s);
}
}
}
compile_set();
vector<int> cands;
for (int i = 0; i < n; i++) {
string s(n, '1');
s[i] = '0';
if (check_element(s)) {
cands.push_back(i);
}
}
assert(sz(cands) == 8);
int cnts[8] {};
for (int i = 0; i < 8; i++) {
for (int j = 0; j < i; j++) {
string s(n, '1');
s[cands[i]] = s[cands[j]] = '0';
if (check_element(s)) {
cnts[i]++;
cnts[j]++;
}
}
}
for (int i = 0; i < 8; i++) {
cerr << cnts[i] << " \n"[i == 7];
}
for (int i = 0; i < 8; i++) {
cerr << acnts[i] << " \n"[i == 7];
}
int arr[6];
bool vis[n] {};
vector<int> ans(n);
for (int i = 0; i < 6; i++) {
arr[i] = cands[find(begin(cnts), end(cnts), acnts[i]) - cnts];
vis[arr[i]] = true;
ans[arr[i]] = i;
dbg(i, arr[i]);
}
for (int i = 0; i < 7; i++) {
for (int j = 0; j < n; j++) {
if (vis[j]) {
continue;
}
string s(n, '0');
for (int k = 0; k < i; k++) {
s[arr[k]] = '1';
}
s[j] = '1';
if (check_element(s)) {
ans[j] |= 1 << i;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
300 KB |
n = 8 |
10 |
Correct |
1 ms |
212 KB |
n = 8 |
11 |
Correct |
1 ms |
212 KB |
n = 8 |
12 |
Correct |
1 ms |
232 KB |
n = 8 |
13 |
Correct |
0 ms |
212 KB |
n = 8 |
14 |
Correct |
1 ms |
212 KB |
n = 8 |
15 |
Correct |
0 ms |
300 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 32 |
2 |
Correct |
0 ms |
212 KB |
n = 32 |
3 |
Correct |
0 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 |
212 KB |
n = 32 |
11 |
Correct |
1 ms |
212 KB |
n = 32 |
12 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
n = 32 |
5 |
Correct |
1 ms |
212 KB |
n = 32 |
6 |
Correct |
1 ms |
212 KB |
n = 32 |
7 |
Correct |
0 ms |
212 KB |
n = 32 |
8 |
Correct |
0 ms |
212 KB |
n = 32 |
9 |
Correct |
0 ms |
212 KB |
n = 32 |
10 |
Correct |
1 ms |
212 KB |
n = 32 |
11 |
Correct |
1 ms |
212 KB |
n = 32 |
12 |
Correct |
1 ms |
212 KB |
n = 32 |
13 |
Correct |
1 ms |
212 KB |
n = 32 |
14 |
Correct |
0 ms |
212 KB |
n = 32 |
15 |
Correct |
1 ms |
212 KB |
n = 32 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
468 KB |
n = 128 |
7 |
Correct |
1 ms |
468 KB |
n = 128 |
8 |
Correct |
1 ms |
468 KB |
n = 128 |
9 |
Correct |
1 ms |
468 KB |
n = 128 |
10 |
Correct |
1 ms |
468 KB |
n = 128 |
11 |
Correct |
1 ms |
468 KB |
n = 128 |
12 |
Correct |
1 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 |
468 KB |
n = 128 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
grader returned WA |
2 |
Halted |
0 ms |
0 KB |
- |