# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151318 | theboatman | "The Lyuboyn" code (IZhO19_lyuboyn) | C++17 | 71 ms | 8568 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 y1 theboatman
#define make_struct(args...) {args}
using namespace std;
typedef long long ll;
const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;
string mask(int x, int n) {
string mask;
while(x) {
mask.push_back(char((x % 2) + '0'));
x /= 2;
}
while(mask.size() < n) {
mask.push_back('0');
}
reverse(mask.begin(), mask.end());
return mask;
}
int dist(int x, int y) {
return __builtin_popcount(x ^ y);
}
void check(vector <int> ans, int k, int t) {
for(int i = 1; i < ans.size(); i++) {
if (dist(ans[i], ans[i - 1]) != k) {
cout << "-1\n";
exit(0);
}
}
if (t && dist(ans.back(), ans[0]) != k) {
cout << "-1\n";
exit(0);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n, k, t;
cin >> n >> k >> t;
string s;
cin >> s;
vector <int> st;
int now = 0, it = 0;
vector <int> used(1 << n);
while(now < (1 << n) && it < int(1e7)) {
int x = (it ^ (it >> k));
if (x < (1 << n) && !used[x]) {
now++;
st.push_back(x);
used[x]++;
}
it++;
}
if (now != (1 << n)) {
return cout << "-1\n", 0;
}
int pos = 0;
for(auto i : st) {
if (mask(i, n) == s) {
break;
}
pos++;
}
vector <int> ans;
for(int i = pos; i < (1 << n); i++) {
ans.push_back(st[i]);
}
for(int i = 0; i < pos; i++) {
ans.push_back(st[i]);
}
check(ans, k, t);
cout << ans.size() << "\n";
for(auto i : ans) {
cout << mask(i, n) << "\n";
}
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... |