Submission #151326

# Submission time Handle Problem Language Result Execution time Memory
151326 2019-09-02T13:10:04 Z theboatman Bigger segments (IZhO19_segments) C++17
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;

typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

int dp[3000][3000];
vector <ll> pref;

ll get(int l, int r) {
    ll res = pref[r];

    return (l ? res - pref[l - 1] : res);
}

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

    int n;
    cin >> n;

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int i = 0; i < n; i++) {
        dp[0][i] = 1;
    }

    pref.resize(n);
    for(int i = 0; i < n; i++) {
        pref[i] = (i ? pref[i - 1] + a[i] : a[i]);
    }

    for(int j = 0; j < n; j++) {
        for(int i = j; i > -1; i--) {
            for(int to = j + 1; to < n; to++) {
                if (get(i, j) <= get(j + 1, to)) {

                    dp[j + 1][to] = max(dp[j + 1][to], dp[i][j] + 1);
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans = max(ans, dp[i][n - 1]);
    }

    cout << ans << "\n";
    return 0;
}
/*
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -