답안 #159068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159068 2019-10-20T12:49:33 Z mrboorger Bigger segments (IZhO19_segments) C++17
37 / 100
160 ms 95620 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];

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];
    for(int i = 0; i < n - 1; ++i)
        for(int j = 1; j <= i + 1; ++j)
    {
        if (dp[i][j] == inf) continue;
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
        {
            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));
            }
        }
    }
    int ans = 0;
    for(int j = 1; j <= n; ++j)
        if (dp[n - 1][j] != inf) ans = j;
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 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 376 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
# 결과 실행 시간 메모리 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 376 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 3324 KB Output is correct
19 Correct 6 ms 3320 KB Output is correct
20 Correct 7 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 5 ms 2552 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 7 ms 3316 KB Output is correct
27 Correct 6 ms 3448 KB Output is correct
28 Correct 5 ms 3320 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 7 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 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 376 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 3324 KB Output is correct
19 Correct 6 ms 3320 KB Output is correct
20 Correct 7 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 5 ms 2552 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 7 ms 3316 KB Output is correct
27 Correct 6 ms 3448 KB Output is correct
28 Correct 5 ms 3320 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 7 ms 3320 KB Output is correct
31 Correct 46 ms 46584 KB Output is correct
32 Correct 46 ms 46584 KB Output is correct
33 Correct 57 ms 46712 KB Output is correct
34 Correct 128 ms 46712 KB Output is correct
35 Correct 160 ms 46716 KB Output is correct
36 Correct 57 ms 46712 KB Output is correct
37 Correct 42 ms 34908 KB Output is correct
38 Correct 29 ms 24056 KB Output is correct
39 Correct 56 ms 46656 KB Output is correct
40 Correct 58 ms 46604 KB Output is correct
41 Correct 157 ms 46716 KB Output is correct
42 Correct 139 ms 46804 KB Output is correct
43 Correct 71 ms 46684 KB Output is correct
44 Correct 158 ms 46688 KB Output is correct
45 Correct 155 ms 46584 KB Output is correct
# 결과 실행 시간 메모리 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 376 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 3324 KB Output is correct
19 Correct 6 ms 3320 KB Output is correct
20 Correct 7 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 5 ms 2552 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 7 ms 3316 KB Output is correct
27 Correct 6 ms 3448 KB Output is correct
28 Correct 5 ms 3320 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 7 ms 3320 KB Output is correct
31 Correct 46 ms 46584 KB Output is correct
32 Correct 46 ms 46584 KB Output is correct
33 Correct 57 ms 46712 KB Output is correct
34 Correct 128 ms 46712 KB Output is correct
35 Correct 160 ms 46716 KB Output is correct
36 Correct 57 ms 46712 KB Output is correct
37 Correct 42 ms 34908 KB Output is correct
38 Correct 29 ms 24056 KB Output is correct
39 Correct 56 ms 46656 KB Output is correct
40 Correct 58 ms 46604 KB Output is correct
41 Correct 157 ms 46716 KB Output is correct
42 Correct 139 ms 46804 KB Output is correct
43 Correct 71 ms 46684 KB Output is correct
44 Correct 158 ms 46688 KB Output is correct
45 Correct 155 ms 46584 KB Output is correct
46 Runtime error 159 ms 95620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 376 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 3324 KB Output is correct
19 Correct 6 ms 3320 KB Output is correct
20 Correct 7 ms 3320 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 5 ms 2552 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 3320 KB Output is correct
25 Correct 5 ms 3320 KB Output is correct
26 Correct 7 ms 3316 KB Output is correct
27 Correct 6 ms 3448 KB Output is correct
28 Correct 5 ms 3320 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 7 ms 3320 KB Output is correct
31 Correct 46 ms 46584 KB Output is correct
32 Correct 46 ms 46584 KB Output is correct
33 Correct 57 ms 46712 KB Output is correct
34 Correct 128 ms 46712 KB Output is correct
35 Correct 160 ms 46716 KB Output is correct
36 Correct 57 ms 46712 KB Output is correct
37 Correct 42 ms 34908 KB Output is correct
38 Correct 29 ms 24056 KB Output is correct
39 Correct 56 ms 46656 KB Output is correct
40 Correct 58 ms 46604 KB Output is correct
41 Correct 157 ms 46716 KB Output is correct
42 Correct 139 ms 46804 KB Output is correct
43 Correct 71 ms 46684 KB Output is correct
44 Correct 158 ms 46688 KB Output is correct
45 Correct 155 ms 46584 KB Output is correct
46 Runtime error 159 ms 95620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -