Submission #993812

# Submission time Handle Problem Language Result Execution time Memory
993812 2024-06-06T12:50:39 Z VMaksimoski008 Bigger segments (IZhO19_segments) C++17
37 / 100
124 ms 262144 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n;
    cin >> n;

    vector<int> v(n+1);
    vector<ll> pref(n+1);
    for(int i=1; i<=n; i++) {
        cin >> v[i];
        pref[i] = pref[i-1] + v[i];
    }

    int dp[n+1][n+1];
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++) dp[i][j] = -1e9;
    for(int i=1; i<=n; i++) dp[1][i] = 1;

    for(int i=2; i<=n; i++) {
        int k = i, mx = -1e9 - 1;
        for(int j=i; j<=n; j++) {
            // for(int k=1; k<i; k++)
            //     if(pref[j] + pref[k-1] >= 2 * pref[i-1]) dp[i][j] = max(dp[i][j], dp[k][i-1] + 1);
            while(k > 1 && pref[j] + pref[k-2] >= 2 * pref[i-1]) mx = max(mx, dp[k-1][i-1]), k--;
            if(k != i) dp[i][j] = mx + 1;
        }
    }

    int 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 50 ms 71004 KB Output is correct
32 Correct 49 ms 71004 KB Output is correct
33 Correct 56 ms 70992 KB Output is correct
34 Correct 48 ms 70924 KB Output is correct
35 Correct 49 ms 71012 KB Output is correct
36 Correct 80 ms 70996 KB Output is correct
37 Correct 43 ms 49244 KB Output is correct
38 Correct 28 ms 31836 KB Output is correct
39 Correct 67 ms 70768 KB Output is correct
40 Correct 54 ms 70996 KB Output is correct
41 Correct 63 ms 70740 KB Output is correct
42 Correct 49 ms 70944 KB Output is correct
43 Correct 61 ms 70748 KB Output is correct
44 Correct 51 ms 70736 KB Output is correct
45 Correct 50 ms 71004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 50 ms 71004 KB Output is correct
32 Correct 49 ms 71004 KB Output is correct
33 Correct 56 ms 70992 KB Output is correct
34 Correct 48 ms 70924 KB Output is correct
35 Correct 49 ms 71012 KB Output is correct
36 Correct 80 ms 70996 KB Output is correct
37 Correct 43 ms 49244 KB Output is correct
38 Correct 28 ms 31836 KB Output is correct
39 Correct 67 ms 70768 KB Output is correct
40 Correct 54 ms 70996 KB Output is correct
41 Correct 63 ms 70740 KB Output is correct
42 Correct 49 ms 70944 KB Output is correct
43 Correct 61 ms 70748 KB Output is correct
44 Correct 51 ms 70736 KB Output is correct
45 Correct 50 ms 71004 KB Output is correct
46 Runtime error 124 ms 262144 KB Execution killed with signal 9
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 50 ms 71004 KB Output is correct
32 Correct 49 ms 71004 KB Output is correct
33 Correct 56 ms 70992 KB Output is correct
34 Correct 48 ms 70924 KB Output is correct
35 Correct 49 ms 71012 KB Output is correct
36 Correct 80 ms 70996 KB Output is correct
37 Correct 43 ms 49244 KB Output is correct
38 Correct 28 ms 31836 KB Output is correct
39 Correct 67 ms 70768 KB Output is correct
40 Correct 54 ms 70996 KB Output is correct
41 Correct 63 ms 70740 KB Output is correct
42 Correct 49 ms 70944 KB Output is correct
43 Correct 61 ms 70748 KB Output is correct
44 Correct 51 ms 70736 KB Output is correct
45 Correct 50 ms 71004 KB Output is correct
46 Runtime error 124 ms 262144 KB Execution killed with signal 9
47 Halted 0 ms 0 KB -