Submission #1066012

# Submission time Handle Problem Language Result Execution time Memory
1066012 2024-08-19T14:09:00 Z manhlinh1501 Bigger segments (IZhO19_segments) C++17
37 / 100
74 ms 98896 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);
        for(int i = 1; i <= N; i++) dp[i][1] = 1;
        for(int i = 1; i <= N; i++) {
            for(int z = 1; z <= i; z++) {
                for(int j = z; j <= i; j++) {
                    if(prefix[i] + prefix[z - 1] >= 2 * prefix[j - 1])
                        dp[i][j] = max(dp[i][j], dp[j - 1][z] + (i != j or j != z));
                    else break;
                }
            }
        }
        int ans = 0;
        for(int i = 1; i <= N; i++) ans = max(ans, dp[N][i]);
        cout << ans << "\n";
    }
}

namespace subtask3 {
    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);
        for(int i = 1; i <= N; i++) dp[i][1] = 1;
        for(int i = 1; i <= N; i++) {
            int j = 1;
            for(int z = 1; z <= i; z++) {
                j = max(j, z);
                while(j < i and prefix[i] + prefix[z - 1] >= 2 * prefix[j]) j++;

                if(prefix[i] + prefix[z - 1] >= 2 * prefix[j - 1])
                    dp[i][j] = max(dp[i][j], dp[j - 1][z] + (i != j or j != z));
            }
        }
        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];
    subtask3::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:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Correct 14 ms 35724 KB Output is correct
3 Correct 13 ms 35592 KB Output is correct
4 Correct 14 ms 35672 KB Output is correct
5 Correct 14 ms 35676 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 15 ms 35672 KB Output is correct
8 Correct 17 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 14 ms 35676 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 13 ms 35676 KB Output is correct
13 Correct 14 ms 35672 KB Output is correct
14 Correct 14 ms 35808 KB Output is correct
15 Correct 16 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Correct 14 ms 35724 KB Output is correct
3 Correct 13 ms 35592 KB Output is correct
4 Correct 14 ms 35672 KB Output is correct
5 Correct 14 ms 35676 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 15 ms 35672 KB Output is correct
8 Correct 17 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 14 ms 35676 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 13 ms 35676 KB Output is correct
13 Correct 14 ms 35672 KB Output is correct
14 Correct 14 ms 35808 KB Output is correct
15 Correct 16 ms 35676 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 22 ms 35772 KB Output is correct
18 Correct 17 ms 35676 KB Output is correct
19 Correct 14 ms 35676 KB Output is correct
20 Correct 17 ms 35676 KB Output is correct
21 Correct 18 ms 35808 KB Output is correct
22 Correct 16 ms 35676 KB Output is correct
23 Correct 14 ms 35736 KB Output is correct
24 Correct 15 ms 35676 KB Output is correct
25 Correct 14 ms 35676 KB Output is correct
26 Correct 18 ms 35644 KB Output is correct
27 Correct 18 ms 35676 KB Output is correct
28 Correct 16 ms 35676 KB Output is correct
29 Correct 14 ms 35676 KB Output is correct
30 Correct 15 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Correct 14 ms 35724 KB Output is correct
3 Correct 13 ms 35592 KB Output is correct
4 Correct 14 ms 35672 KB Output is correct
5 Correct 14 ms 35676 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 15 ms 35672 KB Output is correct
8 Correct 17 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 14 ms 35676 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 13 ms 35676 KB Output is correct
13 Correct 14 ms 35672 KB Output is correct
14 Correct 14 ms 35808 KB Output is correct
15 Correct 16 ms 35676 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 22 ms 35772 KB Output is correct
18 Correct 17 ms 35676 KB Output is correct
19 Correct 14 ms 35676 KB Output is correct
20 Correct 17 ms 35676 KB Output is correct
21 Correct 18 ms 35808 KB Output is correct
22 Correct 16 ms 35676 KB Output is correct
23 Correct 14 ms 35736 KB Output is correct
24 Correct 15 ms 35676 KB Output is correct
25 Correct 14 ms 35676 KB Output is correct
26 Correct 18 ms 35644 KB Output is correct
27 Correct 18 ms 35676 KB Output is correct
28 Correct 16 ms 35676 KB Output is correct
29 Correct 14 ms 35676 KB Output is correct
30 Correct 15 ms 35676 KB Output is correct
31 Correct 31 ms 35672 KB Output is correct
32 Correct 31 ms 35676 KB Output is correct
33 Correct 42 ms 35676 KB Output is correct
34 Correct 32 ms 35700 KB Output is correct
35 Correct 31 ms 35676 KB Output is correct
36 Correct 51 ms 35856 KB Output is correct
37 Correct 37 ms 35676 KB Output is correct
38 Correct 29 ms 35676 KB Output is correct
39 Correct 64 ms 35668 KB Output is correct
40 Correct 37 ms 36112 KB Output is correct
41 Correct 42 ms 35808 KB Output is correct
42 Correct 33 ms 35672 KB Output is correct
43 Correct 40 ms 35672 KB Output is correct
44 Correct 33 ms 35840 KB Output is correct
45 Correct 33 ms 35672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Correct 14 ms 35724 KB Output is correct
3 Correct 13 ms 35592 KB Output is correct
4 Correct 14 ms 35672 KB Output is correct
5 Correct 14 ms 35676 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 15 ms 35672 KB Output is correct
8 Correct 17 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 14 ms 35676 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 13 ms 35676 KB Output is correct
13 Correct 14 ms 35672 KB Output is correct
14 Correct 14 ms 35808 KB Output is correct
15 Correct 16 ms 35676 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 22 ms 35772 KB Output is correct
18 Correct 17 ms 35676 KB Output is correct
19 Correct 14 ms 35676 KB Output is correct
20 Correct 17 ms 35676 KB Output is correct
21 Correct 18 ms 35808 KB Output is correct
22 Correct 16 ms 35676 KB Output is correct
23 Correct 14 ms 35736 KB Output is correct
24 Correct 15 ms 35676 KB Output is correct
25 Correct 14 ms 35676 KB Output is correct
26 Correct 18 ms 35644 KB Output is correct
27 Correct 18 ms 35676 KB Output is correct
28 Correct 16 ms 35676 KB Output is correct
29 Correct 14 ms 35676 KB Output is correct
30 Correct 15 ms 35676 KB Output is correct
31 Correct 31 ms 35672 KB Output is correct
32 Correct 31 ms 35676 KB Output is correct
33 Correct 42 ms 35676 KB Output is correct
34 Correct 32 ms 35700 KB Output is correct
35 Correct 31 ms 35676 KB Output is correct
36 Correct 51 ms 35856 KB Output is correct
37 Correct 37 ms 35676 KB Output is correct
38 Correct 29 ms 35676 KB Output is correct
39 Correct 64 ms 35668 KB Output is correct
40 Correct 37 ms 36112 KB Output is correct
41 Correct 42 ms 35808 KB Output is correct
42 Correct 33 ms 35672 KB Output is correct
43 Correct 40 ms 35672 KB Output is correct
44 Correct 33 ms 35840 KB Output is correct
45 Correct 33 ms 35672 KB Output is correct
46 Runtime error 74 ms 98896 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 35676 KB Output is correct
2 Correct 14 ms 35724 KB Output is correct
3 Correct 13 ms 35592 KB Output is correct
4 Correct 14 ms 35672 KB Output is correct
5 Correct 14 ms 35676 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 15 ms 35672 KB Output is correct
8 Correct 17 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 14 ms 35676 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 13 ms 35676 KB Output is correct
13 Correct 14 ms 35672 KB Output is correct
14 Correct 14 ms 35808 KB Output is correct
15 Correct 16 ms 35676 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 22 ms 35772 KB Output is correct
18 Correct 17 ms 35676 KB Output is correct
19 Correct 14 ms 35676 KB Output is correct
20 Correct 17 ms 35676 KB Output is correct
21 Correct 18 ms 35808 KB Output is correct
22 Correct 16 ms 35676 KB Output is correct
23 Correct 14 ms 35736 KB Output is correct
24 Correct 15 ms 35676 KB Output is correct
25 Correct 14 ms 35676 KB Output is correct
26 Correct 18 ms 35644 KB Output is correct
27 Correct 18 ms 35676 KB Output is correct
28 Correct 16 ms 35676 KB Output is correct
29 Correct 14 ms 35676 KB Output is correct
30 Correct 15 ms 35676 KB Output is correct
31 Correct 31 ms 35672 KB Output is correct
32 Correct 31 ms 35676 KB Output is correct
33 Correct 42 ms 35676 KB Output is correct
34 Correct 32 ms 35700 KB Output is correct
35 Correct 31 ms 35676 KB Output is correct
36 Correct 51 ms 35856 KB Output is correct
37 Correct 37 ms 35676 KB Output is correct
38 Correct 29 ms 35676 KB Output is correct
39 Correct 64 ms 35668 KB Output is correct
40 Correct 37 ms 36112 KB Output is correct
41 Correct 42 ms 35808 KB Output is correct
42 Correct 33 ms 35672 KB Output is correct
43 Correct 40 ms 35672 KB Output is correct
44 Correct 33 ms 35840 KB Output is correct
45 Correct 33 ms 35672 KB Output is correct
46 Runtime error 74 ms 98896 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -