답안 #420751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420751 2021-06-08T13:43:47 Z juancarlovieri Cigle (COI21_cigle) C++17
0 / 100
5 ms 5292 KB
#include <bits/stdc++.h>
using namespace std;

int dp[5005][5005];
int pref[5005][5005];

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 1; i < n; ++i) {
    int cur = 0, prev = 0, v = 0;
    int i2 = i;
    for (int j = i; j < n; ++j) {
      cur += arr[j];
      while (i2 && prev < cur - arr[j]) {
        --i2;
        prev += arr[i2];
      }
      if (i2 && prev == cur - arr[j]) {
        if (prev) ++v;
        --i2;
        prev += arr[i2];
      }
      dp[i][j] = pref[i - 1][i2] + v;
      if (i != j) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      pref[j][i] = max(pref[j][i], dp[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans = max(ans, dp[i][n - 1]);
  cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5196 KB Output is correct
2 Incorrect 5 ms 5292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -