#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
int count(int x, int y) {
return __builtin_popcount((x ^ y));
}
string int2s(int x, int siz) {
string rs;
while (x) {
rs += char('0' + (x & 1));
x >>= 1;
}
while (sz(rs) < siz) rs += '0';
return rs;
}
void solve() {
int n, k, t; cin >> n >> k >> t;
string S; cin >> S;
if (k % 2 == 0) {
cout << "-1\n";
return;
}
auto solve1 = [&](int N) {
vector<int> rs = {0, 1};
int cur = 2;
while (rs.size() < N) {
int cs = sz(rs) - 1;
for (int j = cs; j >= 0; j--) rs.pb(rs[j] + cur);
cur *= 2;
}
return rs;
};
auto solve = [&](int N, int K, auto&&self) -> vector<int> {
int bts = 31 - __builtin_clz(N);
if (K == 1) return solve1(N);
if (K == bts - 1) {
auto rs = solve1(N);
// cout << N << ' ' << K << '\n';
// for (int u : rs) cout << u << ' ';
// cout << '\n';
for (int i = 0; i < sz(rs); i += 2) rs[i] = N - rs[i] - 1;
return rs;
}
auto lol = self(N / 2, K, self);
// for (int u : lol) cout << u << ' ';
// cout << '\n';
for (int i = 0; i < sz(lol); i++) {
for (int j = i + 1; j < sz(lol); j++) {
if (count(lol[i], lol[j]) == K - 1 && count(lol[(i + 1) % (N / 2)], lol[(j + 1) % (N / 2)]) == K - 1) {
vector<int> haha;
int id = (i + 1) % (N / 2);
for (int j = 0; j < N / 2 - 1; j++) {
haha.pb(lol[id]);
id = (id + 1) % (N / 2);
}
haha.pb(lol[i]);
haha.pb(lol[j] + N / 2);
id = (j + N / 2 - 1) % (N / 2);
for (int j = 0; j < N / 2 - 1; j++) {
haha.pb(lol[id] + N / 2);
id = (id - 1 + N / 2) % (N / 2);
}
return haha;
}
}
}
assert(false);
};
auto LOL = solve((1 << n), k, solve);
cout << (1 << n) << '\n';
//for (auto u : LOL) cout << int2s(u, n) << '\n';
for (int i = 0; i < sz(LOL); i++) {
if (int2s(LOL[i], n) == S) {
for (int j= 0; j < sz(LOL); j++) cout << int2s(LOL[(i + j) % sz(LOL)], n) << '\n';
return;
}
}
// auto solve2 = [&](int N, auto&&self) -> vector<int> {
// if (N == 2) return {3};
// if (N == 3) return {6, 3, 6};
// auto ans = self(N - 2, self);
// int X = 0;
// for (int i = 0; i < sz(ans); i++) X = (X ^ ans[i]);
// int start2 = 0;
// for (int val = 0; val < (1 << (N - 2)); val++) {
// if (count(0, val) == 1 && count(X, val) == 1) start2 = val;
// }
// assert(start2);
// vector<int> newans;
// vector<int> lol = {0, 2, 3, 1};
// for (int i = 0; i < 4; i++) {
// for (int u : ans) newans.pb(u);
// if (i < 3) {
// newans.pb((start2^X)+(lol[i+1]^lol[i])*(1<<(N-2)));
// }
// }
// return newans;
// };
// vector<int> rs = solve2(n, solve2);
// int XR = 0;
// for (auto &u : rs) XR ^= u;
// rs.pb(XR);
// vector<int> ans;
// for (int i = 0; i < (1 << n); i++) {
// if (count(i, 0) == k && count(i, rs[0]) == k) {
// int cur1 = 0, cur2 = i;
// for (int j = 0; j < (1 << n); j++) {
// if (j % 2 == 0) {
// ans.pb(cur1);
// cur1 ^= rs[j >> 1];
// } else {
// ans.pb(cur2);
// cur2 ^= rs[((j >> 1) + 1) % sz(rs)];
// }
// }
// break;
// }
// }
// cout << sz(ans) << '\n';
// for (int i = 0; i < sz(ans); i++) {
// if (int2s(ans[i], n) == S) {
// int cur = i, cnt = sz(ans);
// while (cnt) {
// cout << int2s(ans[cur], n) << '\n';
// cur = cur + 1;
// if (cur >= sz(ans)) cur = 0;
// cnt--;
// }
// return;
// }
// }
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |