# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330747 | AlexLuchianov | "The Lyuboyn" code (IZhO19_lyuboyn) | C++14 | 330 ms | 6748 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 <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 18;
std::vector<int> gray(int n) {
std::vector<int> v;
if(n == 1) {
v.push_back(0);
v.push_back(1);
return v;
} else {
std::vector<int> v2 = gray(n - 1);
std::vector<int> v3 = v2;
std::reverse(v3.begin(), v3.end());
for(int i = 0; i < v3.size(); i++)
v2.push_back(v3[i] + (1 << (n - 1)));
return v2;
}
}
class IndependentSet{
private:
std::vector<std::pair<int,int>> v;
public:
IndependentSet() {
}
int reduce(int number) {
for(int i = 0; i < v.size(); i++)
if((1 << v[i].first) & number)
number ^= v[i].second;
return number;
}
void add_set(int number) {
number = reduce(number);
for(int i = 0; i < nmax; i++)
if((1 << i) & number) {
v.push_back({i, number});
return ;
}
}
};
void print(int number, int n) {
for(int i = n - 1; 0 <= i; i--)
std::cout << (0 < ((1 << i) & number));
std::cout << '\n';
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int n, k, t;
std::cin >> n >> k >> t;
IndependentSet myset;
std::vector<int> target;
for(int i = 0; i < (1 << n); i++)
if(k == __builtin_popcount(i) && 0 < myset.reduce(i)) {
target.push_back(i);
myset.add_set(i);
}
std::vector<int> aux = gray(n);
if(target.size() == n) {
std::cout << (1 << n) << '\n';
int start = 0;
for(int i = n - 1; 0 <= i; i--) {
char ch;
std::cin >> ch;
ch -= '0';
start |= (ch<<i);
}
print(start, n);
for(int i = 1; i < (1 << n); i++) {
for(int j = 0; j < n; j++)
if((aux[i] ^ aux[i - 1]) == (1 << j))
start ^= target[j];
print(start, n);
}
} else
std::cout << -1;
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... |