#include <vector>
#include <iostream>
#include <assert.h>
#include "messy.h"
using namespace std;
string start;
vector<int> ans, ans2;
void flip(string& s, int i) {s[i] = ((s[i] - '0') ^ 1) + '0';}
void ask(int L, int R, string s)
{
if (L < R)
{
int M = L + R >> 1;
for (int i = M + 1; i <= R; i++)
{
flip(s, i);
add_element(s);
flip(s, i);
}
for (int i = M + 1; i <= R; i++) {flip(s, i);}
ask(L, M, s);
for (int i = L; i <= R; i++) {flip(s, i);}
ask(M + 1, R, s);
}
}
void solve(int L, int R, string s)
{
if (L < R)
{
int M = L + R >> 1, idx = L;
for (int i = L; i <= R; i++)
{
flip(s, ans[i]);
if (!check_element(s)) {flip(s, ans[i]); swap(ans[i], ans[idx++]);}
else {flip(s, ans[i]);}
}
assert(idx == M + 1);
for (int i = M + 1; i <= R; i++) {flip(s, ans[i]);}
solve(L, M, s);
for (int i = L; i <= R; i++) {flip(s, ans[i]);}
solve(M + 1, R, s);
}
}
vector<int> restore_permutation(int n, int w, int r)
{
for (int i = 0; i < n; i++) {start.push_back('0'); ans.push_back(i); ans2.push_back(0);}
ask(0, n - 1, start);
compile_set();
solve(0, n - 1, start);
for (int i = 0; i < ans.size(); i++) {ans2[ans[i]] = i;}
return ans2;
}
Compilation message
messy.cpp: In function 'void ask(int, int, std::string)':
messy.cpp:18:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
18 | int M = L + R >> 1;
| ~~^~~
messy.cpp: In function 'void solve(int, int, std::string)':
messy.cpp:36:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int M = L + R >> 1, idx = L;
| ~~^~~
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < ans.size(); i++) {ans2[ans[i]] = i;}
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
n = 8 |
2 |
Correct |
0 ms |
256 KB |
n = 8 |
3 |
Correct |
1 ms |
384 KB |
n = 8 |
4 |
Correct |
1 ms |
256 KB |
n = 8 |
5 |
Correct |
0 ms |
256 KB |
n = 8 |
6 |
Correct |
1 ms |
256 KB |
n = 8 |
7 |
Correct |
0 ms |
256 KB |
n = 8 |
8 |
Correct |
0 ms |
256 KB |
n = 8 |
9 |
Correct |
0 ms |
256 KB |
n = 8 |
10 |
Correct |
0 ms |
256 KB |
n = 8 |
11 |
Correct |
0 ms |
256 KB |
n = 8 |
12 |
Correct |
1 ms |
256 KB |
n = 8 |
13 |
Correct |
0 ms |
256 KB |
n = 8 |
14 |
Correct |
0 ms |
256 KB |
n = 8 |
15 |
Correct |
0 ms |
256 KB |
n = 8 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
n = 32 |
2 |
Correct |
1 ms |
384 KB |
n = 32 |
3 |
Correct |
1 ms |
384 KB |
n = 32 |
4 |
Correct |
1 ms |
384 KB |
n = 32 |
5 |
Correct |
1 ms |
384 KB |
n = 32 |
6 |
Correct |
1 ms |
384 KB |
n = 32 |
7 |
Correct |
1 ms |
384 KB |
n = 32 |
8 |
Correct |
1 ms |
384 KB |
n = 32 |
9 |
Correct |
1 ms |
384 KB |
n = 32 |
10 |
Correct |
1 ms |
512 KB |
n = 32 |
11 |
Correct |
1 ms |
384 KB |
n = 32 |
12 |
Correct |
1 ms |
384 KB |
n = 32 |
13 |
Correct |
1 ms |
384 KB |
n = 32 |
14 |
Correct |
1 ms |
384 KB |
n = 32 |
15 |
Correct |
1 ms |
384 KB |
n = 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
n = 32 |
2 |
Correct |
1 ms |
384 KB |
n = 32 |
3 |
Correct |
1 ms |
384 KB |
n = 32 |
4 |
Correct |
1 ms |
384 KB |
n = 32 |
5 |
Correct |
1 ms |
384 KB |
n = 32 |
6 |
Correct |
1 ms |
384 KB |
n = 32 |
7 |
Correct |
1 ms |
384 KB |
n = 32 |
8 |
Correct |
1 ms |
384 KB |
n = 32 |
9 |
Correct |
1 ms |
384 KB |
n = 32 |
10 |
Correct |
1 ms |
384 KB |
n = 32 |
11 |
Correct |
1 ms |
384 KB |
n = 32 |
12 |
Correct |
1 ms |
384 KB |
n = 32 |
13 |
Correct |
1 ms |
384 KB |
n = 32 |
14 |
Correct |
1 ms |
384 KB |
n = 32 |
15 |
Correct |
1 ms |
384 KB |
n = 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
n = 128 |
2 |
Correct |
2 ms |
512 KB |
n = 128 |
3 |
Correct |
2 ms |
512 KB |
n = 128 |
4 |
Correct |
2 ms |
512 KB |
n = 128 |
5 |
Correct |
2 ms |
512 KB |
n = 128 |
6 |
Correct |
2 ms |
512 KB |
n = 128 |
7 |
Correct |
2 ms |
512 KB |
n = 128 |
8 |
Correct |
2 ms |
512 KB |
n = 128 |
9 |
Correct |
2 ms |
512 KB |
n = 128 |
10 |
Correct |
2 ms |
512 KB |
n = 128 |
11 |
Correct |
2 ms |
512 KB |
n = 128 |
12 |
Correct |
3 ms |
512 KB |
n = 128 |
13 |
Correct |
2 ms |
512 KB |
n = 128 |
14 |
Correct |
2 ms |
512 KB |
n = 128 |
15 |
Correct |
2 ms |
512 KB |
n = 128 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
n = 128 |
2 |
Correct |
2 ms |
512 KB |
n = 128 |
3 |
Correct |
3 ms |
512 KB |
n = 128 |
4 |
Correct |
3 ms |
512 KB |
n = 128 |
5 |
Correct |
2 ms |
512 KB |
n = 128 |
6 |
Correct |
2 ms |
512 KB |
n = 128 |
7 |
Correct |
2 ms |
512 KB |
n = 128 |
8 |
Correct |
2 ms |
512 KB |
n = 128 |
9 |
Correct |
2 ms |
512 KB |
n = 128 |
10 |
Correct |
3 ms |
512 KB |
n = 128 |
11 |
Correct |
2 ms |
512 KB |
n = 128 |
12 |
Correct |
2 ms |
512 KB |
n = 128 |
13 |
Correct |
2 ms |
512 KB |
n = 128 |
14 |
Correct |
3 ms |
512 KB |
n = 128 |
15 |
Correct |
2 ms |
512 KB |
n = 128 |