#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
const ld eps = 1e-6;
const int mod = 1e9 + 7;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;
vec<vec<int>> gen(int n)
{
if (n == 1)
{
return {{0}, {1}};
}
vec<vec<int>> g = gen(n - 1);
vec<vec<int>> res;
for (auto &x : g)
{
res.pb({});
res.back().pb(0);
for (int &b : x) res.back().pb(b);
}
reverse(all(g));
for (auto &x : g)
{
res.pb({});
res.back().pb(1);
for (int &b : x) res.back().pb(b);
}
return res;
}
int differ(int x, int y)
{
int res = 0;
for (int b = 0; b < 20; b++)
{
if (((x >> b) & 1) != ((y >> b) & 1)) res++;
}
return res;
}
void solve()
{
int n, k, t, s;
cin >> n >> k >> t >> s;
if (k == 1 && s == 0)
{
vec<vec<int>> res = gen(n);
cout << sz(res) << "\n";
for (auto &x : res)
{
for (int &b : x) cout << b;
cout << "\n";
}
return;
}
if (k % 2 == 0)
{
cout << -1;
return;
}
n = 1 << n;
vec<vec<bool>> can(1 << n, vec<bool>(n));
can[1][0] = true;
vec<vec<int>> from(1 << n, vec<int>(n, -1));
for (int mask = 0; mask < (1 << n); mask++)
{
for (int last = 0; last < n; last++)
{
if (((mask >> last) & 1) == 0) continue;
if (!can[mask][last]) continue;
for (int to = 0; to < n; to++)
{
if ((mask >> to) & 1) continue;
if (differ(last, to) == k)
{
can[mask | (1 << to)][to] = true;
from[mask | (1 << to)][to] = last;
}
}
}
}
int mask = (1 << n) - 1, j = -1;
for (int i = 0; i < n; i++)
{
if (can[mask][i] && differ(0, i) == k)
{
j = i;
break;
}
}
vec<int> ans;
while (mask > 0)
{
ans.pb(j);
int fr = from[mask][j];
mask ^= (1 << j);
j = fr;
}
reverse(all(ans));
cout << sz(ans) << "\n";
for (int &x : ans)
{
for (int b = 0; b < 4; b++)
{
if ((x >> b) & 1) cout << 1;
else cout << 0;
}
cout << "\n";
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Expected EOLN |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
15656 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
1 ms |
212 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
329 ms |
116080 KB |
Ok |
2 |
Correct |
148 ms |
49796 KB |
Ok |
3 |
Correct |
1 ms |
468 KB |
Ok |
4 |
Correct |
0 ms |
324 KB |
Ok |
5 |
Correct |
1 ms |
340 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
329 ms |
116080 KB |
Ok |
2 |
Correct |
148 ms |
49796 KB |
Ok |
3 |
Correct |
1 ms |
468 KB |
Ok |
4 |
Correct |
0 ms |
324 KB |
Ok |
5 |
Correct |
1 ms |
340 KB |
Ok |
6 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |