답안 #420701

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

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

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<vector<int>> dp(N, vector<int>(N));

  for (int mid = N - 1; mid >= 1; mid--) {
    for (int i = N - 2; i >= mid; i--) {
      dp[mid][i] = max(dp[mid][i], dp[mid][i + 1]);
    }
    // [mid - 1, mid] as splitting point
    int sumLft = 0;
    int sumRgt = 0;
    int cost = 0;
    int ptr = mid;
    for (int i = mid - 1; i >= 0; i--) {
      sumLft += A[i];
      while (ptr < N && sumRgt < sumLft) {
        sumRgt += A[ptr];
        ptr += 1;
      }
      cost += (sumLft == sumRgt);
      if (i > 0 && ptr < N) {
        dp[i - 1][mid - 1] = max(dp[i - 1][mid - 1], dp[mid][ptr] + cost);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, dp[0][i]);
  }

  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1228 KB Output is correct
2 Incorrect 2 ms 1228 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -