Submission #389528

# Submission time Handle Problem Language Result Execution time Memory
389528 2021-04-14T07:06:33 Z cheissmart Binary Subsequences (info1cup17_binary) C++14
0 / 100
900 ms 52756 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << "): " << #x << " is " << (x) << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e3 + 7, M = 1e9 + 7;

int dp[N][N], mn_len[N][N], ans[N], mn[N];
int who[N];

void add(int& a, int b) {
    a += b;
    if(a >= M) a -= M;
}

signed main()
{
    ios::sync_with_stdio(0), cin.tie(0);

    memset(mn_len, 0x3f, sizeof mn_len);
    memset(mn, 0x3f, sizeof mn);
    dp[0][0] = 1;
    mn_len[0][0] = 0;
    for(int i = 0; i <= 2000; i++)
        for(int j = 0; i + j <= 2000; j++) {
            // add 0
            if(i + j + 1 <= 2000) {
                add(dp[i + j + 1][j], dp[i][j]);
                if(mn_len[i][j] + 1 < mn_len[i + j + 1][j]) {
                    mn_len[i + j + 1][j] = mn_len[i][j] + 1;
                }
            }
            // add 1
            if(i + j + 1 <= 2000) {
                add(dp[i][i + j + 1], dp[i][j]);
                if(mn_len[i][j] + 1 < mn_len[i][i + j + 1]) {
                    mn_len[i][i + j + 1] = mn_len[i][j] + 1;
                }
            }
            add(ans[i + j], dp[i][j]);
            if(mn_len[i][j] < mn[i + j])
                who[i + j] = i, mn[i + j] = mn_len[i][j];
        }

    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int k;
        cin >> k;
        cout << ans[k] << '\n';
        int x = who[k], y = k - x;
        while(x || y) {
            if(x > y) cout << 0, x -= y + 1;
            else cout << 1, y -= x + 1;
        }
        cout << '\n';
    }

}
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 31760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 52756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1099 ms 52676 KB Time limit exceeded
2 Halted 0 ms 0 KB -