Submission #1035549

# Submission time Handle Problem Language Result Execution time Memory
1035549 2024-07-26T11:49:50 Z tvladm2009 Cigle (COI21_cigle) C++17
0 / 100
3 ms 3420 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define x first
#define y second
#define sz(a) a.size()

typedef long long ll;

const int N = 5e3 + 7;

int a[N];
ll dp[N][N], mx[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i - 1; ++j) {
            mx[j] = dp[j][i - 1];
        }
        for (int j = 1; j <= i - 1; ++j) {
            mx[j] = max(mx[j], mx[j - 1]);
        }
        ll sa = 0;
        ll sb = 0;
        ll x = 0;
        int cnt = 0;
        int pos = i - 1;
        for (int j = i; j <= n; ++j) {
            sb += a[j];
            while (pos >= 1 && sa < sb) {
                sa += a[pos];
                pos--;
            }
            if (pos > 0 && sa == sb) {
                cnt++;
                x = max(x, mx[pos] + cnt);
            }
            dp[i][j + 1] = x;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) 
        ans = max(ans, dp[i][n]);
    cout << ans << "\n";
    return 0;
}
 

# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 2 ms 3416 KB Output is correct
3 Incorrect 2 ms 3420 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -