// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr<<*a<<" \n"[next(a)==b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
void printb(vector<int> v){
int n = __lg(v.size());
cout << v.size() << '\n';
for(auto i: v){
for(int j = n - 1; j >= 0; --j)
cout << ((i & (1<<j)) ? 1 : 0);
cout << '\n';
}
}
vector<int> solvek1(int n){
vector<int> ans = {0, 1};
FOO(i,2,n){
vector<int> b = ans;
reverse(AI(b));
for(auto &j: b) j += (1<<(i-1));
for(auto j: b) ans.pb(j);
}
return ans;
}
vector<int> addk(int k, int n, vector<int> v){
vector<int> h = solvek1(k);
vector<int> ans;
int msk = (((1<<k)-1) << n);
FOR(st, h.size()){
FOR(x, v.size()){
int id = st + x; if(id > v.size()) id -= v.size();
int i = v[id];
i ^= (h[st]<<n);
if(x & 1) i ^= msk;
ans.pb(i);
}
}
return ans;
}
int n, k, t, s;
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k >> t >> s;
if(k % 2 == 0 or k >= n){
puts("-1");
return 0;
}
if(k == 1 and s == 0){
vector<int> ans = solvek1(n);
printb(ans);
return 0;
}
vector<int> ans = solvek1(n - k + 1);
ans = addk(k - 1, n - k + 1, ans);
printb(ans);
return 0;
if(k == 3 and s == 0){
n -= 2;
vector<int> ans = solvek1(n);
cout << ans.size() * 4 << '\n';
const int d[4] = {0, 1, 3, 2};
for(int st = 0; st < 4; ++st){
for(int x = 0; x < ans.size(); ++x){
int i = ans[(st + x) % ans.size()];
i ^= d[st] << n;
if(x & 1) i ^= 3 << n;
for(int j = n + 1; j >= 0; --j)
cout << ((i & (1<<j)) ? 1 : 0);
cout << '\n';
}
}
return 0;
}
return 0;
}
Compilation message
lyuboyn.cpp: In function 'std::vector<int> addk(int, int, std::vector<int>)':
lyuboyn.cpp:9:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,n) for(int i = 0; i < (n); ++i)
| ^
lyuboyn.cpp:47:2: note: in expansion of macro 'FOR'
47 | FOR(st, h.size()){
| ^~~
lyuboyn.cpp:9:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,n) for(int i = 0; i < (n); ++i)
| ^
lyuboyn.cpp:48:3: note: in expansion of macro 'FOR'
48 | FOR(x, v.size()){
| ^~~
lyuboyn.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | int id = st + x; if(id > v.size()) id -= v.size();
| ~~~^~~~~~~~~~
lyuboyn.cpp: In function 'int32_t main()':
lyuboyn.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int x = 0; x < ans.size(); ++x){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
The output is neither -1 nor the length of the answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
0 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
0 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
7588 KB |
Ok |
2 |
Correct |
129 ms |
3876 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
0 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Incorrect |
8 ms |
620 KB |
The values in the output sequence are not pairwise distinct! |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
268 ms |
7520 KB |
The values in the output sequence are not pairwise distinct! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
7588 KB |
Ok |
2 |
Correct |
129 ms |
3876 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
0 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Incorrect |
8 ms |
620 KB |
The values in the output sequence are not pairwise distinct! |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
3940 KB |
The values in the output sequence are not pairwise distinct! |
2 |
Halted |
0 ms |
0 KB |
- |