#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
const int maxn = 210;
int p[maxn];
void write(string s)
{
vector<int> pos;
for (int i = 0; i < s.size(); i++)
if (s[i] == '1')
pos.push_back(i);
if (pos.size() == 1) return;
if (pos.size() == 2)
{
s[pos[0]] = '0';
add_element(s);
return;
}
int mid = pos.size()/2;
for (int i = 0; i < mid; i++)
{
s[pos[i]] = '0';
add_element(s);
s[pos[i]] = '1';
}
for (int i = mid; i < pos.size(); i++)
s[pos[i]] = '0';
write(s);
for (int i = 0; i < mid; i++)
s[pos[i]] = '0';
for (int i = mid; i < pos.size(); i++)
s[pos[i]] = '1';
write(s);
}
void read(string s, string match)
{
vector<int> pos[2];
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '1')
pos[0].push_back(i);
if (match[i] == '1')
pos[1].push_back(i);
}
if (pos[0].size() == 1)
{
p[pos[1][0]] = pos[0][0];
return;
}
string match2, match3;
for (int i = 0; i < match.size(); i++)
match2 += '0', match3 += '0';
for (int i = 0; i < pos[1].size(); i++)
{
match[pos[1][i]] = '0';
if (check_element(match)) match2[pos[1][i]] = '1';
else match3[pos[1][i]] = '1';
match[pos[1][i]] = '1';
}
int mid = pos[0].size()/2;
for (int i = mid; i < pos[0].size(); i++)
s[pos[0][i]] = '0';
if (pos[0].size() == 2)
s[pos[0][1]] = '0';
read(s, match2);
for (int i = mid; i < pos[0].size(); i++)
s[pos[0][i]] = '1';
for (int i = 0; i < mid; i++)
s[pos[0][i]] = '0';
if (pos[0].size() == 2)
s[pos[0][1]] = '1', s[pos[0][0]] = '0';
read(s, match3);
}
vector<int> restore_permutation(int n, int w, int r)
{
string s, match;
for (int i = 0; i < n; i++)
{
s += '1';
match += '1';
}
write(s);
compile_set();
read(s, match);
vector<int> ans;
for (int i = 0; i < n; i++)
ans.push_back(p[i]);
return ans;
}
Compilation message
messy.cpp: In function 'void write(std::string)':
messy.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < s.size(); i++)
| ~~^~~~~~~~~~
messy.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = mid; i < pos.size(); i++)
| ~~^~~~~~~~~~~~
messy.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = mid; i < pos.size(); i++)
| ~~^~~~~~~~~~~~
messy.cpp: In function 'void read(std::string, std::string)':
messy.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < s.size(); i++)
| ~~^~~~~~~~~~
messy.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i < match.size(); i++)
| ~~^~~~~~~~~~~~~~
messy.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < pos[1].size(); i++)
| ~~^~~~~~~~~~~~~~~
messy.cpp:85:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int i = mid; i < pos[0].size(); i++)
| ~~^~~~~~~~~~~~~~~
messy.cpp:93:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = mid; i < pos[0].size(); i++)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n = 8 |
2 |
Correct |
1 ms |
204 KB |
n = 8 |
3 |
Correct |
1 ms |
204 KB |
n = 8 |
4 |
Correct |
0 ms |
204 KB |
n = 8 |
5 |
Correct |
0 ms |
204 KB |
n = 8 |
6 |
Correct |
0 ms |
204 KB |
n = 8 |
7 |
Correct |
0 ms |
204 KB |
n = 8 |
8 |
Correct |
0 ms |
204 KB |
n = 8 |
9 |
Correct |
0 ms |
204 KB |
n = 8 |
10 |
Correct |
0 ms |
204 KB |
n = 8 |
11 |
Correct |
0 ms |
204 KB |
n = 8 |
12 |
Correct |
0 ms |
204 KB |
n = 8 |
13 |
Correct |
0 ms |
204 KB |
n = 8 |
14 |
Correct |
1 ms |
204 KB |
n = 8 |
15 |
Correct |
0 ms |
204 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n = 32 |
2 |
Correct |
1 ms |
204 KB |
n = 32 |
3 |
Correct |
1 ms |
204 KB |
n = 32 |
4 |
Correct |
1 ms |
204 KB |
n = 32 |
5 |
Correct |
1 ms |
204 KB |
n = 32 |
6 |
Correct |
1 ms |
204 KB |
n = 32 |
7 |
Correct |
1 ms |
204 KB |
n = 32 |
8 |
Correct |
1 ms |
204 KB |
n = 32 |
9 |
Correct |
1 ms |
204 KB |
n = 32 |
10 |
Correct |
1 ms |
204 KB |
n = 32 |
11 |
Correct |
1 ms |
204 KB |
n = 32 |
12 |
Correct |
1 ms |
204 KB |
n = 32 |
13 |
Correct |
1 ms |
204 KB |
n = 32 |
14 |
Correct |
1 ms |
204 KB |
n = 32 |
15 |
Correct |
1 ms |
204 KB |
n = 32 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n = 32 |
2 |
Correct |
1 ms |
204 KB |
n = 32 |
3 |
Correct |
1 ms |
204 KB |
n = 32 |
4 |
Correct |
1 ms |
204 KB |
n = 32 |
5 |
Correct |
1 ms |
204 KB |
n = 32 |
6 |
Correct |
1 ms |
204 KB |
n = 32 |
7 |
Correct |
1 ms |
204 KB |
n = 32 |
8 |
Correct |
1 ms |
204 KB |
n = 32 |
9 |
Correct |
1 ms |
204 KB |
n = 32 |
10 |
Correct |
1 ms |
204 KB |
n = 32 |
11 |
Correct |
1 ms |
204 KB |
n = 32 |
12 |
Correct |
1 ms |
204 KB |
n = 32 |
13 |
Correct |
1 ms |
204 KB |
n = 32 |
14 |
Correct |
1 ms |
204 KB |
n = 32 |
15 |
Correct |
1 ms |
204 KB |
n = 32 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
n = 128 |
2 |
Correct |
2 ms |
460 KB |
n = 128 |
3 |
Correct |
2 ms |
460 KB |
n = 128 |
4 |
Correct |
2 ms |
460 KB |
n = 128 |
5 |
Correct |
2 ms |
460 KB |
n = 128 |
6 |
Correct |
2 ms |
460 KB |
n = 128 |
7 |
Correct |
2 ms |
460 KB |
n = 128 |
8 |
Correct |
2 ms |
460 KB |
n = 128 |
9 |
Correct |
2 ms |
460 KB |
n = 128 |
10 |
Correct |
2 ms |
460 KB |
n = 128 |
11 |
Correct |
2 ms |
460 KB |
n = 128 |
12 |
Correct |
2 ms |
460 KB |
n = 128 |
13 |
Correct |
2 ms |
460 KB |
n = 128 |
14 |
Correct |
2 ms |
460 KB |
n = 128 |
15 |
Correct |
2 ms |
460 KB |
n = 128 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
n = 128 |
2 |
Correct |
2 ms |
460 KB |
n = 128 |
3 |
Correct |
2 ms |
460 KB |
n = 128 |
4 |
Correct |
2 ms |
460 KB |
n = 128 |
5 |
Correct |
2 ms |
460 KB |
n = 128 |
6 |
Correct |
2 ms |
460 KB |
n = 128 |
7 |
Correct |
2 ms |
460 KB |
n = 128 |
8 |
Correct |
2 ms |
460 KB |
n = 128 |
9 |
Correct |
2 ms |
460 KB |
n = 128 |
10 |
Correct |
2 ms |
460 KB |
n = 128 |
11 |
Correct |
2 ms |
416 KB |
n = 128 |
12 |
Correct |
2 ms |
468 KB |
n = 128 |
13 |
Correct |
2 ms |
420 KB |
n = 128 |
14 |
Correct |
2 ms |
496 KB |
n = 128 |
15 |
Correct |
2 ms |
460 KB |
n = 128 |