답안 #899042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899042 2024-01-05T11:51:47 Z d4xn Bigger segments (IZhO19_segments) C++17
100 / 100
107 ms 45384 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 5e5+1, inf = LLONG_MAX;

int n, a[N], pre[N];
vector<pair<int, int>> dp[N];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  a[0] = pre[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = a[i] + pre[i-1];
  }

  dp[0].push_back(make_pair(0, 0));
  for (int i = 0; i < n; i++) {  
    pair<int, int> p = make_pair(-inf, inf);
    for (auto& [x, y] : dp[i]) {
      if (x > p.first) {
        p = make_pair(x, y);
      }
      else if (x == p.first) {
        p.second = min(p.second, y);
      }
    }

    // no hago grupo nuevo
    dp[i+1].push_back(make_pair(p.first, p.second + a[i+1]));

    // hago grupo nuevo
    int l = i+1;
    int r = n+1;
    while (l < r) {
      int mid = (l+r)/2;

      int x = pre[mid] - pre[i];
      if (x >= p.second) r = mid;
      else l = mid+1;
    }
    if (r == n+1) continue; // cogiendo todos sigue siendo menor

    dp[l].push_back(make_pair(p.first+1, pre[l] - pre[i]));
  }

  int ans = -inf;
  for (auto& [x, y] : dp[n]) {
    ans = max(ans, x);
  }
  cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14964 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14964 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 3 ms 15028 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 14988 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 3 ms 14936 KB Output is correct
27 Correct 3 ms 14940 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14964 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 3 ms 15028 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 14988 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 3 ms 14936 KB Output is correct
27 Correct 3 ms 14940 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 3 ms 14940 KB Output is correct
31 Correct 3 ms 14940 KB Output is correct
32 Correct 4 ms 14968 KB Output is correct
33 Correct 4 ms 14940 KB Output is correct
34 Correct 3 ms 14940 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 4 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 4 ms 14940 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 3 ms 14936 KB Output is correct
43 Correct 3 ms 14940 KB Output is correct
44 Correct 3 ms 14940 KB Output is correct
45 Correct 3 ms 14964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14964 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 3 ms 15028 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 14988 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 3 ms 14936 KB Output is correct
27 Correct 3 ms 14940 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 3 ms 14940 KB Output is correct
31 Correct 3 ms 14940 KB Output is correct
32 Correct 4 ms 14968 KB Output is correct
33 Correct 4 ms 14940 KB Output is correct
34 Correct 3 ms 14940 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 4 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 4 ms 14940 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 3 ms 14936 KB Output is correct
43 Correct 3 ms 14940 KB Output is correct
44 Correct 3 ms 14940 KB Output is correct
45 Correct 3 ms 14964 KB Output is correct
46 Correct 14 ms 20060 KB Output is correct
47 Correct 21 ms 21852 KB Output is correct
48 Correct 23 ms 21852 KB Output is correct
49 Correct 18 ms 21592 KB Output is correct
50 Correct 18 ms 21596 KB Output is correct
51 Correct 23 ms 22124 KB Output is correct
52 Correct 13 ms 17496 KB Output is correct
53 Correct 9 ms 16476 KB Output is correct
54 Correct 20 ms 22108 KB Output is correct
55 Correct 25 ms 21844 KB Output is correct
56 Correct 16 ms 21596 KB Output is correct
57 Correct 16 ms 21712 KB Output is correct
58 Correct 17 ms 21716 KB Output is correct
59 Correct 16 ms 21660 KB Output is correct
60 Correct 17 ms 21592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14964 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 3 ms 15028 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 14988 KB Output is correct
25 Correct 3 ms 14940 KB Output is correct
26 Correct 3 ms 14936 KB Output is correct
27 Correct 3 ms 14940 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
29 Correct 3 ms 14940 KB Output is correct
30 Correct 3 ms 14940 KB Output is correct
31 Correct 3 ms 14940 KB Output is correct
32 Correct 4 ms 14968 KB Output is correct
33 Correct 4 ms 14940 KB Output is correct
34 Correct 3 ms 14940 KB Output is correct
35 Correct 3 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 4 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 4 ms 14940 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 3 ms 14936 KB Output is correct
43 Correct 3 ms 14940 KB Output is correct
44 Correct 3 ms 14940 KB Output is correct
45 Correct 3 ms 14964 KB Output is correct
46 Correct 14 ms 20060 KB Output is correct
47 Correct 21 ms 21852 KB Output is correct
48 Correct 23 ms 21852 KB Output is correct
49 Correct 18 ms 21592 KB Output is correct
50 Correct 18 ms 21596 KB Output is correct
51 Correct 23 ms 22124 KB Output is correct
52 Correct 13 ms 17496 KB Output is correct
53 Correct 9 ms 16476 KB Output is correct
54 Correct 20 ms 22108 KB Output is correct
55 Correct 25 ms 21844 KB Output is correct
56 Correct 16 ms 21596 KB Output is correct
57 Correct 16 ms 21712 KB Output is correct
58 Correct 17 ms 21716 KB Output is correct
59 Correct 16 ms 21660 KB Output is correct
60 Correct 17 ms 21592 KB Output is correct
61 Correct 59 ms 35568 KB Output is correct
62 Correct 74 ms 39612 KB Output is correct
63 Correct 99 ms 44532 KB Output is correct
64 Correct 94 ms 44748 KB Output is correct
65 Correct 79 ms 43348 KB Output is correct
66 Correct 107 ms 45224 KB Output is correct
67 Correct 85 ms 39316 KB Output is correct
68 Correct 47 ms 29276 KB Output is correct
69 Correct 93 ms 45384 KB Output is correct
70 Correct 91 ms 44296 KB Output is correct
71 Correct 67 ms 43348 KB Output is correct
72 Correct 71 ms 43460 KB Output is correct
73 Correct 72 ms 43268 KB Output is correct
74 Correct 78 ms 43436 KB Output is correct
75 Correct 73 ms 43352 KB Output is correct