Submission #520607

#TimeUsernameProblemLanguageResultExecution timeMemory
520607VimmerCigle (COI21_cigle)C++14
48 / 100
1088 ms196488 KiB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) (ll)x.size()
#define N 1000500
#define pri(x) cout << x << endl
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

int f[5005][5005][2];

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    memset(f, -1, sizeof f);

    int n;

    cin >> n;

    int a[n], ans = 0;

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

    for (int i = 0; i < n; i++)
        f[0][i][0] = 0;

    for (int r = 0; r < n; r++)
        for (int l = 0; l <= r; l++)
            for (int t = 0; t < 2; t++)
                if (f[l][r][t] != -1)
                {
                    int kl = f[l][r][t];

                    int u = r, sm = 0, cur = 0;

                    for (int nw = r + 1; nw < n; nw++)
                    {
                        if (cur == sm && u != l - 1 && nw != r + 1 && u != r)
                            kl++;

                        cur += a[nw];

                        while (u >= l && cur > sm)
                        {
                            sm += a[u];

                            u--;
                        }

                        f[r + 1][nw][t ^ 1] = max(f[r + 1][nw][t ^ 1], kl);

                        ans = max(ans, kl);
                    }
                }

    pri(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...