Submission #169367

# Submission time Handle Problem Language Result Execution time Memory
169367 2019-12-20T06:27:15 Z SamAnd Bigger segments (IZhO19_segments) C++17
100 / 100
147 ms 18912 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 500005;

int n;
int a[N];
long long p[N];

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

pair<int, long long> mer(const pair<int, long long>& l, const pair<int, long long>& r)
{
    if (l.first > r.first)
        return l;
    if (l.first < r.first)
        return r;
    if (l.second < r.second)
        return l;
    return r;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        p[i] = p[i - 1] + a[i];
    for (int i = 0; i < n; ++i)
    {
        dp[i + 1] = mer(dp[i + 1], m_p(dp[i].first, dp[i].second + a[i + 1]));
        int l = i + 1, r = n;
        int ans = -1;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (p[m] - p[i] >= dp[i].second)
            {
                ans = m;
                r = m - 1;
            }
            else
                l = m + 1;
        }
        if (ans != -1)
            dp[ans] = mer(dp[ans], m_p(dp[i].first + 1, p[ans] - p[i]));
    }
    printf("%d\n", dp[n].first);
    return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
segments.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 476 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 404 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 476 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 404 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 19 ms 3448 KB Output is correct
47 Correct 23 ms 3576 KB Output is correct
48 Correct 26 ms 3832 KB Output is correct
49 Correct 26 ms 3960 KB Output is correct
50 Correct 23 ms 4092 KB Output is correct
51 Correct 31 ms 4088 KB Output is correct
52 Correct 16 ms 2168 KB Output is correct
53 Correct 11 ms 1404 KB Output is correct
54 Correct 21 ms 3324 KB Output is correct
55 Correct 26 ms 4088 KB Output is correct
56 Correct 20 ms 3576 KB Output is correct
57 Correct 20 ms 3452 KB Output is correct
58 Correct 21 ms 3580 KB Output is correct
59 Correct 21 ms 3704 KB Output is correct
60 Correct 21 ms 3704 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 476 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 404 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 19 ms 3448 KB Output is correct
47 Correct 23 ms 3576 KB Output is correct
48 Correct 26 ms 3832 KB Output is correct
49 Correct 26 ms 3960 KB Output is correct
50 Correct 23 ms 4092 KB Output is correct
51 Correct 31 ms 4088 KB Output is correct
52 Correct 16 ms 2168 KB Output is correct
53 Correct 11 ms 1404 KB Output is correct
54 Correct 21 ms 3324 KB Output is correct
55 Correct 26 ms 4088 KB Output is correct
56 Correct 20 ms 3576 KB Output is correct
57 Correct 20 ms 3452 KB Output is correct
58 Correct 21 ms 3580 KB Output is correct
59 Correct 21 ms 3704 KB Output is correct
60 Correct 21 ms 3704 KB Output is correct
61 Correct 89 ms 16028 KB Output is correct
62 Correct 100 ms 16004 KB Output is correct
63 Correct 112 ms 16376 KB Output is correct
64 Correct 133 ms 18592 KB Output is correct
65 Correct 110 ms 18900 KB Output is correct
66 Correct 147 ms 18808 KB Output is correct
67 Correct 121 ms 15224 KB Output is correct
68 Correct 60 ms 7800 KB Output is correct
69 Correct 101 ms 15100 KB Output is correct
70 Correct 122 ms 18912 KB Output is correct
71 Correct 89 ms 15992 KB Output is correct
72 Correct 99 ms 16392 KB Output is correct
73 Correct 99 ms 16888 KB Output is correct
74 Correct 100 ms 17372 KB Output is correct
75 Correct 100 ms 17372 KB Output is correct