답안 #1067096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067096 2024-08-20T11:17:06 Z manhlinh1501 Bigger segments (IZhO19_segments) C++17
100 / 100
85 ms 46416 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 5e5 + 5;
using pli = pair<i64, int>;
using pii = pair<int, int>;
const i64 oo64 = 5e15 + 5;

int N;
int a[MAXN];
i64 b[MAXN];
pli dp[MAXN];
vector<int> g[MAXN];

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for(int i = 1; i <= N; i++) b[i] = b[i - 1] + a[i];

    pii cur = {0, 0};
    for(int i = 1; i <= N; i++) {
        for(int j : g[i]) {
            if(dp[j].second > cur.second or (dp[j].second == cur.second and j > cur.first))
                cur = {j, dp[j].second};
        }
        dp[i] = {b[i] - b[cur.first], cur.second + 1};
        int p = lower_bound(b + 1, b + N + 1, dp[i].first + b[i]) - b;
        g[p].emplace_back(i);
    }
    cout << dp[N].second;
}

/**
4
2 3 1 7
**/

/**
5
6 2 3 9 13
**/

/**
3
3 1 2
**/

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14940 KB Output is correct
12 Correct 2 ms 14940 KB Output is correct
13 Correct 2 ms 14940 KB Output is correct
14 Correct 2 ms 14936 KB Output is correct
15 Correct 3 ms 14948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14940 KB Output is correct
12 Correct 2 ms 14940 KB Output is correct
13 Correct 2 ms 14940 KB Output is correct
14 Correct 2 ms 14936 KB Output is correct
15 Correct 3 ms 14948 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14936 KB Output is correct
18 Correct 2 ms 14940 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 2 ms 14940 KB Output is correct
22 Correct 2 ms 14996 KB Output is correct
23 Correct 2 ms 14940 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
27 Correct 2 ms 14940 KB Output is correct
28 Correct 2 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 2 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14940 KB Output is correct
12 Correct 2 ms 14940 KB Output is correct
13 Correct 2 ms 14940 KB Output is correct
14 Correct 2 ms 14936 KB Output is correct
15 Correct 3 ms 14948 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14936 KB Output is correct
18 Correct 2 ms 14940 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 2 ms 14940 KB Output is correct
22 Correct 2 ms 14996 KB Output is correct
23 Correct 2 ms 14940 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
27 Correct 2 ms 14940 KB Output is correct
28 Correct 2 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 2 ms 14940 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 3 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 2 ms 14940 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 3 ms 14936 KB Output is correct
37 Correct 3 ms 14940 KB Output is correct
38 Correct 3 ms 14940 KB Output is correct
39 Correct 3 ms 14940 KB Output is correct
40 Correct 3 ms 15008 KB Output is correct
41 Correct 3 ms 14940 KB Output is correct
42 Correct 4 ms 14968 KB Output is correct
43 Correct 3 ms 14952 KB Output is correct
44 Correct 2 ms 15012 KB Output is correct
45 Correct 2 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14940 KB Output is correct
12 Correct 2 ms 14940 KB Output is correct
13 Correct 2 ms 14940 KB Output is correct
14 Correct 2 ms 14936 KB Output is correct
15 Correct 3 ms 14948 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14936 KB Output is correct
18 Correct 2 ms 14940 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 2 ms 14940 KB Output is correct
22 Correct 2 ms 14996 KB Output is correct
23 Correct 2 ms 14940 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
27 Correct 2 ms 14940 KB Output is correct
28 Correct 2 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 2 ms 14940 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 3 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 2 ms 14940 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 3 ms 14936 KB Output is correct
37 Correct 3 ms 14940 KB Output is correct
38 Correct 3 ms 14940 KB Output is correct
39 Correct 3 ms 14940 KB Output is correct
40 Correct 3 ms 15008 KB Output is correct
41 Correct 3 ms 14940 KB Output is correct
42 Correct 4 ms 14968 KB Output is correct
43 Correct 3 ms 14952 KB Output is correct
44 Correct 2 ms 15012 KB Output is correct
45 Correct 2 ms 14940 KB Output is correct
46 Correct 9 ms 18656 KB Output is correct
47 Correct 13 ms 19804 KB Output is correct
48 Correct 16 ms 20284 KB Output is correct
49 Correct 16 ms 21624 KB Output is correct
50 Correct 19 ms 21848 KB Output is correct
51 Correct 18 ms 20572 KB Output is correct
52 Correct 11 ms 18780 KB Output is correct
53 Correct 8 ms 15964 KB Output is correct
54 Correct 16 ms 19568 KB Output is correct
55 Correct 17 ms 21340 KB Output is correct
56 Correct 15 ms 21336 KB Output is correct
57 Correct 14 ms 20060 KB Output is correct
58 Correct 13 ms 20572 KB Output is correct
59 Correct 16 ms 21516 KB Output is correct
60 Correct 15 ms 21340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14940 KB Output is correct
12 Correct 2 ms 14940 KB Output is correct
13 Correct 2 ms 14940 KB Output is correct
14 Correct 2 ms 14936 KB Output is correct
15 Correct 3 ms 14948 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14936 KB Output is correct
18 Correct 2 ms 14940 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 2 ms 14940 KB Output is correct
22 Correct 2 ms 14996 KB Output is correct
23 Correct 2 ms 14940 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
27 Correct 2 ms 14940 KB Output is correct
28 Correct 2 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 2 ms 14940 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 3 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 2 ms 14940 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 3 ms 14936 KB Output is correct
37 Correct 3 ms 14940 KB Output is correct
38 Correct 3 ms 14940 KB Output is correct
39 Correct 3 ms 14940 KB Output is correct
40 Correct 3 ms 15008 KB Output is correct
41 Correct 3 ms 14940 KB Output is correct
42 Correct 4 ms 14968 KB Output is correct
43 Correct 3 ms 14952 KB Output is correct
44 Correct 2 ms 15012 KB Output is correct
45 Correct 2 ms 14940 KB Output is correct
46 Correct 9 ms 18656 KB Output is correct
47 Correct 13 ms 19804 KB Output is correct
48 Correct 16 ms 20284 KB Output is correct
49 Correct 16 ms 21624 KB Output is correct
50 Correct 19 ms 21848 KB Output is correct
51 Correct 18 ms 20572 KB Output is correct
52 Correct 11 ms 18780 KB Output is correct
53 Correct 8 ms 15964 KB Output is correct
54 Correct 16 ms 19568 KB Output is correct
55 Correct 17 ms 21340 KB Output is correct
56 Correct 15 ms 21336 KB Output is correct
57 Correct 14 ms 20060 KB Output is correct
58 Correct 13 ms 20572 KB Output is correct
59 Correct 16 ms 21516 KB Output is correct
60 Correct 15 ms 21340 KB Output is correct
61 Correct 36 ms 29896 KB Output is correct
62 Correct 42 ms 31568 KB Output is correct
63 Correct 60 ms 35556 KB Output is correct
64 Correct 84 ms 41296 KB Output is correct
65 Correct 72 ms 46416 KB Output is correct
66 Correct 85 ms 40016 KB Output is correct
67 Correct 63 ms 36004 KB Output is correct
68 Correct 33 ms 27988 KB Output is correct
69 Correct 64 ms 35408 KB Output is correct
70 Correct 78 ms 44116 KB Output is correct
71 Correct 68 ms 43344 KB Output is correct
72 Correct 51 ms 38292 KB Output is correct
73 Correct 62 ms 42252 KB Output is correct
74 Correct 67 ms 44624 KB Output is correct
75 Correct 65 ms 44708 KB Output is correct