Submission #336869

# Submission time Handle Problem Language Result Execution time Memory
336869 2020-12-17T05:51:04 Z boykut Bigger segments (IZhO19_segments) C++14
27 / 100
324 ms 8428 KB
#include <bits/stdc++.h>
using namespace std;

#define linl long long

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  
  vector < int > a(n);
  
  for (int & to : a) {
    cin >> to;
  }
  
  int max = 0;
  
  if (n <= 500) {
    set < pair < int64_t, int > > dp[n];
    vector < int64_t > prefsum(n);
    
    auto get = [&] (int left, int right) -> int64_t {
      return prefsum[right] - (left == 0 ? 0ll : prefsum[left - 1]);
    };
    
    for (int i = 0; i < n; i++) {
      prefsum[i] = a[i];
      if (i)
        prefsum[i] += prefsum[i - 1];
    }
    
    for (int i = 0; i < n; i++) {
      dp[i].insert(make_pair(get(0, i), 1));
    }
    
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= i; j++) {
        int mx = -1;
        for (auto it : dp[j - 1]) {
          if (it.first <= get(j, i)) {
            if (mx == -1 || it.second > mx)
              mx = it.second;
          }
        }
        if (mx == -1) continue;
        dp[i].insert(make_pair(get(j, i), mx + 1));
      }
    }
    
    int mx = 0;
    for (auto it : dp[n - 1]) {
      if (it.second > mx)
        mx = it.second;
    }
    cout << mx << '\n';
  }
  return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:18:7: warning: unused variable 'max' [-Wunused-variable]
   18 |   int max = 0;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 206 ms 6680 KB Output is correct
18 Correct 277 ms 7916 KB Output is correct
19 Correct 197 ms 6940 KB Output is correct
20 Correct 324 ms 8300 KB Output is correct
21 Correct 238 ms 7916 KB Output is correct
22 Correct 86 ms 5228 KB Output is correct
23 Correct 38 ms 2924 KB Output is correct
24 Correct 226 ms 7788 KB Output is correct
25 Correct 234 ms 8044 KB Output is correct
26 Correct 267 ms 8428 KB Output is correct
27 Correct 117 ms 5100 KB Output is correct
28 Correct 246 ms 8172 KB Output is correct
29 Correct 290 ms 8300 KB Output is correct
30 Correct 305 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 206 ms 6680 KB Output is correct
18 Correct 277 ms 7916 KB Output is correct
19 Correct 197 ms 6940 KB Output is correct
20 Correct 324 ms 8300 KB Output is correct
21 Correct 238 ms 7916 KB Output is correct
22 Correct 86 ms 5228 KB Output is correct
23 Correct 38 ms 2924 KB Output is correct
24 Correct 226 ms 7788 KB Output is correct
25 Correct 234 ms 8044 KB Output is correct
26 Correct 267 ms 8428 KB Output is correct
27 Correct 117 ms 5100 KB Output is correct
28 Correct 246 ms 8172 KB Output is correct
29 Correct 290 ms 8300 KB Output is correct
30 Correct 305 ms 8172 KB Output is correct
31 Incorrect 1 ms 364 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 206 ms 6680 KB Output is correct
18 Correct 277 ms 7916 KB Output is correct
19 Correct 197 ms 6940 KB Output is correct
20 Correct 324 ms 8300 KB Output is correct
21 Correct 238 ms 7916 KB Output is correct
22 Correct 86 ms 5228 KB Output is correct
23 Correct 38 ms 2924 KB Output is correct
24 Correct 226 ms 7788 KB Output is correct
25 Correct 234 ms 8044 KB Output is correct
26 Correct 267 ms 8428 KB Output is correct
27 Correct 117 ms 5100 KB Output is correct
28 Correct 246 ms 8172 KB Output is correct
29 Correct 290 ms 8300 KB Output is correct
30 Correct 305 ms 8172 KB Output is correct
31 Incorrect 1 ms 364 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 206 ms 6680 KB Output is correct
18 Correct 277 ms 7916 KB Output is correct
19 Correct 197 ms 6940 KB Output is correct
20 Correct 324 ms 8300 KB Output is correct
21 Correct 238 ms 7916 KB Output is correct
22 Correct 86 ms 5228 KB Output is correct
23 Correct 38 ms 2924 KB Output is correct
24 Correct 226 ms 7788 KB Output is correct
25 Correct 234 ms 8044 KB Output is correct
26 Correct 267 ms 8428 KB Output is correct
27 Correct 117 ms 5100 KB Output is correct
28 Correct 246 ms 8172 KB Output is correct
29 Correct 290 ms 8300 KB Output is correct
30 Correct 305 ms 8172 KB Output is correct
31 Incorrect 1 ms 364 KB Output isn't correct
32 Halted 0 ms 0 KB -