This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int Z = 100;
mt19937 rng(time(nullptr));
int n, k, t, s;
string ss;
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k >> t >> ss;
s = 0;
for (int i = 0; i < n; i++) {
s += (1 << (n-i-1)) * (ss[i] == '1');
}
vector<int> ans(1 << n);
for (int i = 0; i < (1 << n); i++) {
ans[i] = i;
if (i == s) swap(ans[0], ans[i]);
}
bool ok = 0;
shuffle(ans.begin()+1, ans.end(), rng);
for (int z = 0; z < Z; z++) {
int x = -1;
for (int i = 0; i+1 < n; i++) {
if (__builtin_popcount(ans[i] ^ ans[i-1]) != k) {
x = i;
break;
}
}
if (x == -1) {
ok = 1;
break;
}
int y = -1;
for (int i = x+2; i+1 < n; i++) {
if (__builtin_popcount(ans[i] ^ ans[i-1]) != k &&
__builtin_popcount(ans[x] ^ ans[i]) == k &&
__builtin_popcount(ans[x+1] ^ ans[i+1]) == k) {
y = i;
break;
}
}
reverse(ans.begin()+x+1, ans.begin()+y);
}
if (!ok) cout << "-1\n";
else {
cout << (1 << n) << "\n";
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < n; j++) {
if ((ans[i] >> (n-j-1)) & 1) ss[j] = '1';
else ss[j] = '0';
}
cout << ss << "\n";
}
}
}
# | 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... |