//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 4e4;
const int M = 4500;
const int L = 19;
vector<int> g[N];
bool flag[N];
vector<int> ans;
bool used[N];
void dfs(int v){
used[v] = true;
ans.push_back(v);
for (int u : g[v]){
if (!used[u]) dfs(u);
}
}
bool check(vector<int> &v, int t){
for (int i = 1; i < v.size(); i++){
if (!flag[v[i - 1] ^ v[i]]) return false;
}
return (t == 0 || flag[v[0] ^ v.back()]);
}
void solve(int TC) {
int n, k, t, s;
cin >> n >> k >> t >> s;
vector<int> v;
for (int mask = 0; mask < (1 << n); mask++){
if (__builtin_popcount(mask) == k) v.push_back(mask), flag[mask] = true;
}
for (int x = 0; x < (1 << n); x++){
for (int y : v){
g[x].push_back(x ^ y);
//cout << x << ' ' << y << endl;
}
}
dfs(s);
if (check(ans, t) && ans.size() == (1 << n)){
cout << ans.size() << endl;
for (int x : ans){
for (int i = n - 1; i >= 0; i--){
cout << ((x & (1 << i)) > 0);
}
cout << endl;
}
} else cout << -1;
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
//cin >> TC;
for (int test = 1; test <= TC; test++) {
debug(test);
solve(test);
}
if (llololcal) cerr << endl << "Time: " << getCurrentTime() * 1000 << " ms" << endl;
return 0;
}
Compilation message
lyuboyn.cpp: In function 'bool check(std::vector<int>&, int)':
lyuboyn.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
lyuboyn.cpp: In function 'void solve(int)':
lyuboyn.cpp:78:37: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
78 | if (check(ans, t) && ans.size() == (1 << n)){
| ~~~~~~~~~~~^~~~~~~~~~~
lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:18:20: warning: statement has no effect [-Wunused-value]
18 | #define debug(...) 42
| ^~
lyuboyn.cpp:105:9: note: in expansion of macro 'debug'
105 | debug(test);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
24812 KB |
Output -1 while solution exists |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
24812 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
29164 KB |
Ok |
2 |
Runtime error |
335 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
969 ms |
80676 KB |
Ok |
2 |
Correct |
486 ms |
52580 KB |
Ok |
3 |
Correct |
18 ms |
24940 KB |
Ok |
4 |
Correct |
15 ms |
24812 KB |
Ok |
5 |
Correct |
19 ms |
24812 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
24812 KB |
Ok |
2 |
Correct |
73 ms |
41836 KB |
Ok |
3 |
Runtime error |
304 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
339 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
969 ms |
80676 KB |
Ok |
2 |
Correct |
486 ms |
52580 KB |
Ok |
3 |
Correct |
18 ms |
24940 KB |
Ok |
4 |
Correct |
15 ms |
24812 KB |
Ok |
5 |
Correct |
19 ms |
24812 KB |
Ok |
6 |
Correct |
16 ms |
24812 KB |
Ok |
7 |
Correct |
73 ms |
41836 KB |
Ok |
8 |
Runtime error |
304 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
430 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |