Submission #159074

# Submission time Handle Problem Language Result Execution time Memory
159074 2019-10-20T13:30:34 Z mrboorger Bigger segments (IZhO19_segments) C++17
37 / 100
161 ms 96096 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include "interactive.h"

#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double
#define sqr(x) (x) * (x)
//#define all(a) a.begin(), a.end()

using namespace std;

const int maxn = 3005;
const ll inf = 1e18;

ll dp[maxn][maxn];
int a[maxn];
ll sum[maxn];
int mx[maxn];

ll f(int l, int r)
{
    return sum[r] - (l > 0 ? sum[l - 1] : 0);
}

int main()
{
#ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
        sum[i] = a[i] + (i > 0 ? sum[i - 1] : 0);
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j <= i + 1; ++j)
            dp[i][j] = inf;
    dp[0][1] = a[0];
    mx[0] = 1;
    for(int i = 0; i < n - 1; ++i)
        for(int j = max(1, mx[i] - 5); j <= mx[i]; ++j)
    {
        if (dp[i][j] == inf) continue;
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
        mx[i + 1] = max(mx[i + 1], j);
        {
            int l = i + 1, r = n - 1;
            int b = n + 1;
            while(l <= r)
            {
                int m = (l + r) / 2;
                if (f(i + 1, m) >= dp[i][j])
                {
                    b = min(b, m);
                    r = m - 1;
                }
                else
                {
                    l = m + 1;
                }
            }
            if (b < n + 1)
            {
                dp[b][j + 1] = min(dp[b][j + 1], f(i + 1, b));
                mx[b] = max(mx[b], j + 1);
            }
        }
    }
    int ans = 0;
    for(int j = 1; j <= n; ++j)
        if (dp[n - 1][j] != inf) ans = j;
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 3320 KB Output is correct
17 Correct 5 ms 3320 KB Output is correct
18 Correct 5 ms 3320 KB Output is correct
19 Correct 4 ms 3320 KB Output is correct
20 Correct 5 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 3 ms 1912 KB Output is correct
24 Correct 4 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 5 ms 3320 KB Output is correct
27 Correct 5 ms 3320 KB Output is correct
28 Correct 4 ms 3324 KB Output is correct
29 Correct 5 ms 3324 KB Output is correct
30 Correct 4 ms 3372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 3320 KB Output is correct
17 Correct 5 ms 3320 KB Output is correct
18 Correct 5 ms 3320 KB Output is correct
19 Correct 4 ms 3320 KB Output is correct
20 Correct 5 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 3 ms 1912 KB Output is correct
24 Correct 4 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 5 ms 3320 KB Output is correct
27 Correct 5 ms 3320 KB Output is correct
28 Correct 4 ms 3324 KB Output is correct
29 Correct 5 ms 3324 KB Output is correct
30 Correct 4 ms 3372 KB Output is correct
31 Correct 44 ms 46712 KB Output is correct
32 Correct 41 ms 46712 KB Output is correct
33 Correct 42 ms 46712 KB Output is correct
34 Correct 42 ms 46712 KB Output is correct
35 Correct 42 ms 46656 KB Output is correct
36 Correct 42 ms 46712 KB Output is correct
37 Correct 32 ms 34936 KB Output is correct
38 Correct 23 ms 24056 KB Output is correct
39 Correct 41 ms 46712 KB Output is correct
40 Correct 43 ms 46712 KB Output is correct
41 Correct 41 ms 46584 KB Output is correct
42 Correct 42 ms 46724 KB Output is correct
43 Correct 42 ms 46716 KB Output is correct
44 Correct 42 ms 46712 KB Output is correct
45 Correct 42 ms 46712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 3320 KB Output is correct
17 Correct 5 ms 3320 KB Output is correct
18 Correct 5 ms 3320 KB Output is correct
19 Correct 4 ms 3320 KB Output is correct
20 Correct 5 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 3 ms 1912 KB Output is correct
24 Correct 4 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 5 ms 3320 KB Output is correct
27 Correct 5 ms 3320 KB Output is correct
28 Correct 4 ms 3324 KB Output is correct
29 Correct 5 ms 3324 KB Output is correct
30 Correct 4 ms 3372 KB Output is correct
31 Correct 44 ms 46712 KB Output is correct
32 Correct 41 ms 46712 KB Output is correct
33 Correct 42 ms 46712 KB Output is correct
34 Correct 42 ms 46712 KB Output is correct
35 Correct 42 ms 46656 KB Output is correct
36 Correct 42 ms 46712 KB Output is correct
37 Correct 32 ms 34936 KB Output is correct
38 Correct 23 ms 24056 KB Output is correct
39 Correct 41 ms 46712 KB Output is correct
40 Correct 43 ms 46712 KB Output is correct
41 Correct 41 ms 46584 KB Output is correct
42 Correct 42 ms 46724 KB Output is correct
43 Correct 42 ms 46716 KB Output is correct
44 Correct 42 ms 46712 KB Output is correct
45 Correct 42 ms 46712 KB Output is correct
46 Runtime error 161 ms 96096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 3320 KB Output is correct
17 Correct 5 ms 3320 KB Output is correct
18 Correct 5 ms 3320 KB Output is correct
19 Correct 4 ms 3320 KB Output is correct
20 Correct 5 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 3 ms 1912 KB Output is correct
24 Correct 4 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 5 ms 3320 KB Output is correct
27 Correct 5 ms 3320 KB Output is correct
28 Correct 4 ms 3324 KB Output is correct
29 Correct 5 ms 3324 KB Output is correct
30 Correct 4 ms 3372 KB Output is correct
31 Correct 44 ms 46712 KB Output is correct
32 Correct 41 ms 46712 KB Output is correct
33 Correct 42 ms 46712 KB Output is correct
34 Correct 42 ms 46712 KB Output is correct
35 Correct 42 ms 46656 KB Output is correct
36 Correct 42 ms 46712 KB Output is correct
37 Correct 32 ms 34936 KB Output is correct
38 Correct 23 ms 24056 KB Output is correct
39 Correct 41 ms 46712 KB Output is correct
40 Correct 43 ms 46712 KB Output is correct
41 Correct 41 ms 46584 KB Output is correct
42 Correct 42 ms 46724 KB Output is correct
43 Correct 42 ms 46716 KB Output is correct
44 Correct 42 ms 46712 KB Output is correct
45 Correct 42 ms 46712 KB Output is correct
46 Runtime error 161 ms 96096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -