# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
181105 | BThero | "The Lyuboyn" code (IZhO19_lyuboyn) | C++17 | 1096 ms | 17336 KiB |
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>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()
using namespace std;
const bool dbg_flg = 1;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
const int inf = 1e9 + 7;
const int MAXN = (1 << 18) + 5;
int n, k, t;
string st;
string arr[MAXN];
bool used[MAXN];
int f(string a, string b) {
assert(a.size() == n && b.size() == n);
int ret = 0;
for (int i = 0; i < n; ++i) {
if (a[i] != b[i]) {
++ret;
}
}
return ret;
}
void printAns() {
cout << (1 << n) << endl;
for (int i = 0; i < (1 << n); ++i) {
cout << arr[i] << endl;
}
exit(0);
}
string str(int x) {
string ret;
while (x > 0) {
ret.pb(x % 2 + '0');
x /= 2;
}
while (ret.size() < n) {
ret.pb('0');
}
reverse(ret.begin(), ret.end());
return ret;
}
void rec(int v) {
if (v == (1 << n) - 1) {
if (t == 1) {
if (f(arr[v], arr[0]) == k) {
printAns();
}
}
else {
printAns();
}
return;
}
for (int x = 0; x < (1 << n); ++x) {
if (!used[x] && f(arr[v], str(x)) == k) {
used[x] = 1;
arr[v + 1] = str(x);
rec(v + 1);
used[x] = 0;
}
}
}
int bin(string s) {
reverse(all(s));
int ret = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '1') {
ret += (1 << i);
}
}
return ret;
}
int main() {
//~ freopen(".in", "r", stdin);
//~ freopen(".out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k >> t;
cin >> st;
arr[0] = st;
used[bin(st)] = 1;
rec(0);
return 0;
}
Compilation message (stderr)
# | 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... |