Submission #336881

# Submission time Handle Problem Language Result Execution time Memory
336881 2020-12-17T06:31:56 Z boykut Bigger segments (IZhO19_segments) C++14
27 / 100
105 ms 1516 KB
#include <bits/stdc++.h>

using namespace std;

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;
  }
  
  vector < int64_t > prefsum(n);
  for (int i = 0; i < n; i++) {
    prefsum[i] = a[i];
    if (i)
      prefsum[i] += prefsum[i - 1];
  }
  
  auto get = [&] (int left, int right) -> int64_t {
    return prefsum[right] - (left == 0 ? 0ll : prefsum[left - 1]);
  };
  
  /*if (n <= 500) {
    set < pair < int64_t, int > > dp[n];
    
    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;
  }*/
  if (n <= 600) {
    vector < vector < bool > > can(n, vector < bool > (n, false));
    vector < vector < int > > dp(n, vector < int > (n, 0));
    
    for (int i = 0; i < n; i++) {
      can[0][i] = true;
      dp[0][i] = 1;
    }
    
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= i; j++) {
        for (int k = 0; k <= j - 1; k++) {
          if (get(k, j - 1) <= get(j, i) && can[k][j - 1]) {
            dp[j][i] = max(dp[j][i], dp[k][j - 1] + 1);
            can[j][i] = true;
          }
        }
      }
    }
    
    int mx = 0;
    for (int i = 0; i < n; i++) {
      mx = max(mx, dp[i][n - 1]);
    }
    cout << mx << '\n';
    return 0;
  }
  return 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 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 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 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 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 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 31 ms 1388 KB Output is correct
17 Correct 61 ms 1388 KB Output is correct
18 Correct 78 ms 1388 KB Output is correct
19 Correct 61 ms 1388 KB Output is correct
20 Correct 82 ms 1388 KB Output is correct
21 Correct 75 ms 1388 KB Output is correct
22 Correct 40 ms 1004 KB Output is correct
23 Correct 17 ms 748 KB Output is correct
24 Correct 78 ms 1388 KB Output is correct
25 Correct 78 ms 1516 KB Output is correct
26 Correct 105 ms 1388 KB Output is correct
27 Correct 41 ms 1388 KB Output is correct
28 Correct 97 ms 1516 KB Output is correct
29 Correct 95 ms 1388 KB Output is correct
30 Correct 80 ms 1388 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 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 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 31 ms 1388 KB Output is correct
17 Correct 61 ms 1388 KB Output is correct
18 Correct 78 ms 1388 KB Output is correct
19 Correct 61 ms 1388 KB Output is correct
20 Correct 82 ms 1388 KB Output is correct
21 Correct 75 ms 1388 KB Output is correct
22 Correct 40 ms 1004 KB Output is correct
23 Correct 17 ms 748 KB Output is correct
24 Correct 78 ms 1388 KB Output is correct
25 Correct 78 ms 1516 KB Output is correct
26 Correct 105 ms 1388 KB Output is correct
27 Correct 41 ms 1388 KB Output is correct
28 Correct 97 ms 1516 KB Output is correct
29 Correct 95 ms 1388 KB Output is correct
30 Correct 80 ms 1388 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 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 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 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 31 ms 1388 KB Output is correct
17 Correct 61 ms 1388 KB Output is correct
18 Correct 78 ms 1388 KB Output is correct
19 Correct 61 ms 1388 KB Output is correct
20 Correct 82 ms 1388 KB Output is correct
21 Correct 75 ms 1388 KB Output is correct
22 Correct 40 ms 1004 KB Output is correct
23 Correct 17 ms 748 KB Output is correct
24 Correct 78 ms 1388 KB Output is correct
25 Correct 78 ms 1516 KB Output is correct
26 Correct 105 ms 1388 KB Output is correct
27 Correct 41 ms 1388 KB Output is correct
28 Correct 97 ms 1516 KB Output is correct
29 Correct 95 ms 1388 KB Output is correct
30 Correct 80 ms 1388 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 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 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 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 31 ms 1388 KB Output is correct
17 Correct 61 ms 1388 KB Output is correct
18 Correct 78 ms 1388 KB Output is correct
19 Correct 61 ms 1388 KB Output is correct
20 Correct 82 ms 1388 KB Output is correct
21 Correct 75 ms 1388 KB Output is correct
22 Correct 40 ms 1004 KB Output is correct
23 Correct 17 ms 748 KB Output is correct
24 Correct 78 ms 1388 KB Output is correct
25 Correct 78 ms 1516 KB Output is correct
26 Correct 105 ms 1388 KB Output is correct
27 Correct 41 ms 1388 KB Output is correct
28 Correct 97 ms 1516 KB Output is correct
29 Correct 95 ms 1388 KB Output is correct
30 Correct 80 ms 1388 KB Output is correct
31 Incorrect 1 ms 364 KB Output isn't correct
32 Halted 0 ms 0 KB -