제출 #1081728

#제출 시각아이디문제언어결과실행 시간메모리
1081728juicyCigle (COI21_cigle)C++17
100 / 100
147 ms81348 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 5e3 + 5;

int n;
int a[N], dp[N][N];

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

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int res = 0;
  for (int i = 2; i <= n; ++i) {
    int k = i - 1, s = a[i - 1], t = 0, cnt = 0;
    dp[i][i] = dp[i - 1][i - 1];
    for (int j = i + 1; j <= n; ++j) {
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      t += a[j - 1];
      while (k && s <= t) {
        cnt += s == t;
        s += a[--k];
      }
      if (k) {
        dp[i][j] = max(dp[i][j], dp[k][i - 1] + cnt);
      }
      res = max(res, dp[i][j]);
    }
    for (int j = 1; j <= i; ++j) {
      dp[j][i] = max(dp[j][i], dp[j - 1][i]);
    }
  }
  cout << res;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...