Submission #979942

# Submission time Handle Problem Language Result Execution time Memory
979942 2024-05-11T17:01:21 Z underwaterkillerwhale Cigle (COI21_cigle) C++17
100 / 100
196 ms 88452 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N = 5e3 + 7;
const ll Mod = 1e9 + 7;
const int szBL = 916;
const ll INF = 1e9;
const int BASE = 137;

int n;
int a[N];
int dp[N][N], f[N];

void solution () {
    cin >> n;
    rep (i, 1, n) cin >> a[i];
    rep (L, 1, n) {
        f[0] = -INF;
        rep (i, 1, L - 1) {
            f[i] = max(f[i - 1], dp[i][L - 1]);
        }
        int ptr = L - 1, curcost = 0, suf = a[L - 1], pre = a[L];
        dp[L][L - 1] = f[L - 1];
        rep (R, L, n) {
            dp[L][R] = max(dp[L][R], dp[L][R - 1]);
            while (ptr > 1 && suf < pre) {
                dp[L][R] = max (dp[L][R], dp[ptr - 1][L - 1] + curcost);
                suf += a[ptr - 1];
                --ptr;
            }
            if (suf == pre) {
                curcost++;
                dp[L][R + 1] = max (dp[L][R + 1], f[ptr - 1] + curcost);
            }
//            cout << L<<","<<R<<" "<<dp[L][R] <<" "<<suf<<","<<pre<<": "<<f[ptr - 1] + curcost<<"\n";
            pre += a[R + 1];
        }

    }
    int res = 0;
    rep (L, 1, n) {
        res = max(res, dp[L][n]);
    }
    cout << res <<"\n";
}



#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);

int main () {
//    file("c");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll num_Test = 1;
//    cin >> num_Test;
    while(num_Test--)
        solution();
}
/*
18 3
2 5
6 21
13 19
9 17
14 17
19 20
2 16
2 10
9 14
19 20
14 16
1 3
17 19
14 21
18 19
4 7
5 12
1 13

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2476 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 3 ms 9276 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 3 ms 9308 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2476 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
22 Correct 2 ms 9052 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 3 ms 9276 KB Output is correct
25 Correct 2 ms 9052 KB Output is correct
26 Correct 2 ms 9052 KB Output is correct
27 Correct 3 ms 9052 KB Output is correct
28 Correct 3 ms 9052 KB Output is correct
29 Correct 3 ms 9308 KB Output is correct
30 Correct 2 ms 9052 KB Output is correct
31 Correct 3 ms 9052 KB Output is correct
32 Correct 2 ms 9052 KB Output is correct
33 Correct 2 ms 9052 KB Output is correct
34 Correct 2 ms 9052 KB Output is correct
35 Correct 2 ms 9052 KB Output is correct
36 Correct 2 ms 9052 KB Output is correct
37 Correct 2 ms 9052 KB Output is correct
38 Correct 2 ms 9208 KB Output is correct
39 Correct 3 ms 9052 KB Output is correct
40 Correct 3 ms 9296 KB Output is correct
41 Correct 2 ms 9052 KB Output is correct
42 Correct 2 ms 9052 KB Output is correct
43 Correct 2 ms 9052 KB Output is correct
44 Correct 2 ms 9052 KB Output is correct
45 Correct 3 ms 9052 KB Output is correct
46 Correct 2 ms 9212 KB Output is correct
47 Correct 2 ms 9052 KB Output is correct
48 Correct 3 ms 9052 KB Output is correct
49 Correct 2 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2476 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
22 Correct 2 ms 9052 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 3 ms 9276 KB Output is correct
25 Correct 2 ms 9052 KB Output is correct
26 Correct 2 ms 9052 KB Output is correct
27 Correct 3 ms 9052 KB Output is correct
28 Correct 3 ms 9052 KB Output is correct
29 Correct 3 ms 9308 KB Output is correct
30 Correct 2 ms 9052 KB Output is correct
31 Correct 3 ms 9052 KB Output is correct
32 Correct 2 ms 9052 KB Output is correct
33 Correct 2 ms 9052 KB Output is correct
34 Correct 2 ms 9052 KB Output is correct
35 Correct 2 ms 9052 KB Output is correct
36 Correct 2 ms 9052 KB Output is correct
37 Correct 2 ms 9052 KB Output is correct
38 Correct 2 ms 9208 KB Output is correct
39 Correct 3 ms 9052 KB Output is correct
40 Correct 3 ms 9296 KB Output is correct
41 Correct 2 ms 9052 KB Output is correct
42 Correct 2 ms 9052 KB Output is correct
43 Correct 2 ms 9052 KB Output is correct
44 Correct 2 ms 9052 KB Output is correct
45 Correct 3 ms 9052 KB Output is correct
46 Correct 2 ms 9212 KB Output is correct
47 Correct 2 ms 9052 KB Output is correct
48 Correct 3 ms 9052 KB Output is correct
49 Correct 2 ms 9052 KB Output is correct
50 Correct 159 ms 88148 KB Output is correct
51 Correct 144 ms 88272 KB Output is correct
52 Correct 149 ms 88148 KB Output is correct
53 Correct 141 ms 88148 KB Output is correct
54 Correct 149 ms 88452 KB Output is correct
55 Correct 139 ms 88148 KB Output is correct
56 Correct 176 ms 88232 KB Output is correct
57 Correct 171 ms 88148 KB Output is correct
58 Correct 176 ms 88312 KB Output is correct
59 Correct 164 ms 88332 KB Output is correct
60 Correct 188 ms 88360 KB Output is correct
61 Correct 160 ms 88232 KB Output is correct
62 Correct 155 ms 88148 KB Output is correct
63 Correct 147 ms 88288 KB Output is correct
64 Correct 152 ms 88288 KB Output is correct
65 Correct 157 ms 88300 KB Output is correct
66 Correct 148 ms 88204 KB Output is correct
67 Correct 152 ms 88148 KB Output is correct
68 Correct 146 ms 88144 KB Output is correct
69 Correct 146 ms 88248 KB Output is correct
70 Correct 196 ms 88332 KB Output is correct
71 Correct 172 ms 88376 KB Output is correct
72 Correct 169 ms 88148 KB Output is correct