Submission #336870

# Submission time Handle Problem Language Result Execution time Memory
336870 2020-12-17T05:51:53 Z boykut Bigger segments (IZhO19_segments) C++14
27 / 100
1500 ms 17964 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 <= 3000) {
    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 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
9 Correct 0 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 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
9 Correct 0 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 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 157 ms 6508 KB Output is correct
18 Correct 274 ms 7896 KB Output is correct
19 Correct 219 ms 6892 KB Output is correct
20 Correct 285 ms 8172 KB Output is correct
21 Correct 241 ms 7660 KB Output is correct
22 Correct 90 ms 5100 KB Output is correct
23 Correct 39 ms 2924 KB Output is correct
24 Correct 265 ms 7916 KB Output is correct
25 Correct 271 ms 7916 KB Output is correct
26 Correct 292 ms 8172 KB Output is correct
27 Correct 119 ms 5100 KB Output is correct
28 Correct 271 ms 8044 KB Output is correct
29 Correct 337 ms 8152 KB Output is correct
30 Correct 291 ms 8044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
9 Correct 0 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 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 157 ms 6508 KB Output is correct
18 Correct 274 ms 7896 KB Output is correct
19 Correct 219 ms 6892 KB Output is correct
20 Correct 285 ms 8172 KB Output is correct
21 Correct 241 ms 7660 KB Output is correct
22 Correct 90 ms 5100 KB Output is correct
23 Correct 39 ms 2924 KB Output is correct
24 Correct 265 ms 7916 KB Output is correct
25 Correct 271 ms 7916 KB Output is correct
26 Correct 292 ms 8172 KB Output is correct
27 Correct 119 ms 5100 KB Output is correct
28 Correct 271 ms 8044 KB Output is correct
29 Correct 337 ms 8152 KB Output is correct
30 Correct 291 ms 8044 KB Output is correct
31 Correct 22 ms 748 KB Output is correct
32 Execution timed out 1577 ms 17964 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
9 Correct 0 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 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 157 ms 6508 KB Output is correct
18 Correct 274 ms 7896 KB Output is correct
19 Correct 219 ms 6892 KB Output is correct
20 Correct 285 ms 8172 KB Output is correct
21 Correct 241 ms 7660 KB Output is correct
22 Correct 90 ms 5100 KB Output is correct
23 Correct 39 ms 2924 KB Output is correct
24 Correct 265 ms 7916 KB Output is correct
25 Correct 271 ms 7916 KB Output is correct
26 Correct 292 ms 8172 KB Output is correct
27 Correct 119 ms 5100 KB Output is correct
28 Correct 271 ms 8044 KB Output is correct
29 Correct 337 ms 8152 KB Output is correct
30 Correct 291 ms 8044 KB Output is correct
31 Correct 22 ms 748 KB Output is correct
32 Execution timed out 1577 ms 17964 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
9 Correct 0 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 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 157 ms 6508 KB Output is correct
18 Correct 274 ms 7896 KB Output is correct
19 Correct 219 ms 6892 KB Output is correct
20 Correct 285 ms 8172 KB Output is correct
21 Correct 241 ms 7660 KB Output is correct
22 Correct 90 ms 5100 KB Output is correct
23 Correct 39 ms 2924 KB Output is correct
24 Correct 265 ms 7916 KB Output is correct
25 Correct 271 ms 7916 KB Output is correct
26 Correct 292 ms 8172 KB Output is correct
27 Correct 119 ms 5100 KB Output is correct
28 Correct 271 ms 8044 KB Output is correct
29 Correct 337 ms 8152 KB Output is correct
30 Correct 291 ms 8044 KB Output is correct
31 Correct 22 ms 748 KB Output is correct
32 Execution timed out 1577 ms 17964 KB Time limit exceeded
33 Halted 0 ms 0 KB -