#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fs first
#define ss second
#define str string
#define all(a) a.begin(), a.end()
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
#define each(x, a) for (auto x : a)
vector<int> ans;
vector<bool> used;
int n, k, t, sx = 0;
bool good(int s1, int s2){
int ans = 0;
while(s1 > 0 or s2 > 0){
ans += (s1 % 2 != s2 % 2);
s1 /= 2;
s2 /= 2;
}
return ans == k;
}
bool dfs(int node, int step){
if(step == (1 << n) - 1){
if(t == 0){
ans.push_back(node);
return true;
}
if(good(sx, node))
ans.push_back(node);
else
return false;
return true;
}
used[node] = 1;
if(k == 1){
for (int i = 0; i < n; i++)
{
if (!used[node ^ (1 << i)] and dfs(node ^ (1 << i), step + 1))
{
ans.push_back(node);
return true;
}
}
}
else{
for (int i = 0; i < (1 << n); i++)
{
if (!used[i] and good(i, node) and dfs(i, step + 1))
{
ans.push_back(node);
return true;
}
}
}
return false;
}
void solve(){
cin >> n >> k >> t;
str s;
cin >> s;
for(int i = s.size() - 1; i >= 0; i --){
if(s[i] == '1'){
sx += (1 << (s.size() - 1 - i));
}
}
used.resize((1 << n));
if(dfs(sx, 0)){
cout << (1 << n) << endl;
reverse(all(ans));
for(int i = 0; i < ans.size(); i ++){
str s = "";
for(int j = 0; j < n; j ++){
if(ans[i] % 2 == 0)
s += '0';
else
s += '1';
ans[i] >>= 1;
}
reverse(all(s));
cout << s << endl;
}
}
else{
cout << -1;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
}
Compilation message
lyuboyn.cpp: In function 'void solve()':
lyuboyn.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < ans.size(); i ++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output -1 while solution exists |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
616 KB |
Ok |
2 |
Execution timed out |
1044 ms |
596 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
18892 KB |
Ok |
2 |
Correct |
28 ms |
9500 KB |
Ok |
3 |
Correct |
1 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output -1 while solution exists |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
2476 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
18892 KB |
Ok |
2 |
Correct |
28 ms |
9500 KB |
Ok |
3 |
Correct |
1 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Incorrect |
0 ms |
348 KB |
Output -1 while solution exists |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |