답안 #500054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500054 2021-12-30T09:54:57 Z RedBoy Bigger segments (IZhO19_segments) C++11
100 / 100
82 ms 13080 KB
#include <iostream>

using namespace std;

const int N = 5e5 + 5;

int n;
long long s[N];
pair<int, int> dp[N];

bool check(int mid, int index)
{
    return s[mid] >= 2 * s[index] - s[dp[index].second - 1];
}

int binarySearch(int index)
{
    int l = index + 1, r = n;
    while(l < r)
    {
        int mid = (l + r) / 2;
        if(check(mid, index))
            r = mid;
        else
            l = mid + 1;
    }

    return (check(l, index) ? l : -1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        s[i] = x + s[i - 1];
    }

    dp[1] = {1, 1};
    for(int i = 1; i <= n; i++)
    {
        dp[i + 1] = max(dp[i + 1], dp[i]);

        int x = binarySearch(i);
        if(x != -1)
            dp[x] = max(dp[x], {dp[i].first + 1, i + 1});
    }

    cout << dp[n].first << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 11 ms 2252 KB Output is correct
47 Correct 13 ms 2340 KB Output is correct
48 Correct 14 ms 2572 KB Output is correct
49 Correct 13 ms 2756 KB Output is correct
50 Correct 13 ms 2848 KB Output is correct
51 Correct 17 ms 2844 KB Output is correct
52 Correct 8 ms 1504 KB Output is correct
53 Correct 5 ms 972 KB Output is correct
54 Correct 11 ms 2092 KB Output is correct
55 Correct 18 ms 2756 KB Output is correct
56 Correct 9 ms 2264 KB Output is correct
57 Correct 10 ms 2244 KB Output is correct
58 Correct 10 ms 2340 KB Output is correct
59 Correct 11 ms 2376 KB Output is correct
60 Correct 11 ms 2372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 11 ms 2252 KB Output is correct
47 Correct 13 ms 2340 KB Output is correct
48 Correct 14 ms 2572 KB Output is correct
49 Correct 13 ms 2756 KB Output is correct
50 Correct 13 ms 2848 KB Output is correct
51 Correct 17 ms 2844 KB Output is correct
52 Correct 8 ms 1504 KB Output is correct
53 Correct 5 ms 972 KB Output is correct
54 Correct 11 ms 2092 KB Output is correct
55 Correct 18 ms 2756 KB Output is correct
56 Correct 9 ms 2264 KB Output is correct
57 Correct 10 ms 2244 KB Output is correct
58 Correct 10 ms 2340 KB Output is correct
59 Correct 11 ms 2376 KB Output is correct
60 Correct 11 ms 2372 KB Output is correct
61 Correct 60 ms 10020 KB Output is correct
62 Correct 65 ms 10036 KB Output is correct
63 Correct 65 ms 10456 KB Output is correct
64 Correct 70 ms 12644 KB Output is correct
65 Correct 62 ms 12996 KB Output is correct
66 Correct 82 ms 12896 KB Output is correct
67 Correct 60 ms 10312 KB Output is correct
68 Correct 30 ms 5276 KB Output is correct
69 Correct 55 ms 9132 KB Output is correct
70 Correct 71 ms 13080 KB Output is correct
71 Correct 43 ms 10064 KB Output is correct
72 Correct 53 ms 10432 KB Output is correct
73 Correct 56 ms 11016 KB Output is correct
74 Correct 56 ms 11324 KB Output is correct
75 Correct 54 ms 11432 KB Output is correct