#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
int dp[2005][2005];
int mn[2005][2005];
int mmn[2005];
int ans[2005];
int tp[2005];
int add(int a, int b) {
a += b;
if (a > MOD) a -= MOD;
return a;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
memset(mmn, 0x3f, sizeof mmn);
memset(mn, 0x3f, sizeof mn);
dp[0][0] = 1;
mn[0][0] = 0;
for (int i = 0; i <= 2000; i++) {
for (int j = 0; i + j <= 2000; j++) {
if (i + j + 1 <= 2000) {
dp[i + j + 1][j] = add(dp[i + j + 1][j], dp[i][j]);
if (mn[i + j + 1][j] > mn[i][j] + 1) {
mn[i + j + 1][j] = mn[i][j] + 1;
}
}
if (i + j + 1 <= 2000) {
dp[i][i + j + 1] = add(dp[i][i + j + 1], dp[i][j]);
if (mn[i][i + j + 1] > mn[i][j] + 1) {
mn[i][i + j + 1] = mn[i][j] + 1;
}
}
ans[i + j] = add(ans[i + j], dp[i][j]);
if (mn[i][j] < mmn[i + j]) {
tp[i + j] = i;
mmn[i + j] = mn[i][j];
}
}
}
int n; cin >> n;
for (int i = 0; i < n; i++) {
int k; cin >> k;
cout << ans[k] << '\n';
int x = tp[k], y = k - x;
while (x || y) {
if (x > y) {
cout << 0 << ' ';
x -= y + 1;
} else {
cout << 1 << ' ';
y -= x + 1;
}
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
63280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1097 ms |
88260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1103 ms |
88264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |