Submission #1065991

# Submission time Handle Problem Language Result Execution time Memory
1065991 2024-08-19T13:55:54 Z manhlinh1501 Bigger segments (IZhO19_segments) C++17
0 / 100
14 ms 35776 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 5e5 + 5;

int N;
int a[MAXN];

namespace subtask {
    const int MAXN = 3e3 + 5;

    int dp[MAXN][MAXN];
    i64 prefix[MAXN];

    void solution() {
        for(int i = 1; i <= N; i++) prefix[i] = prefix[i - 1] + a[i];
        memset(dp, -0x3f, sizeof dp);
        dp[0][0] = 0;
        for(int i = 1; i <= N; i++) {
            for(int j = 0; j <= i; j++) {
                for(int z = 0; z <= j; z++) {
                    if(2 * prefix[j] - prefix[i] <= prefix[z - 1] and (i != j or j != z))
                        dp[i][j] = max(dp[i][j], dp[j][z] + 1);
                }
            }
        }
        int ans = 0;
        for(int i = 1; i <= N; i++) ans = max(ans, dp[N][i]);
        cout << ans << "\n";
    }
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    subtask::solution();
    return (0 ^ 0);
}

/**
4
2 3 1 7
**/

/**
5
6 2 3 9 13
**/

/**
3
3 1 2
**/

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Incorrect 14 ms 35776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Incorrect 14 ms 35776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Incorrect 14 ms 35776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Incorrect 14 ms 35776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Incorrect 14 ms 35776 KB Output isn't correct
3 Halted 0 ms 0 KB -