Submission #19706071


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

void solve() {
  int n; cin >> n;
  vector<int> a(n);
  for(auto &x : a) cin >> x;

  vector<vector<int>> dp(n+1, vector<int>(n+1, 0));

  for(int k=0; k<n; ++k) {
    for(int i=0, j=k; j<=n; ++i, ++j) {
      for(int ni=i-3, nj=j; ni<=i; ++ni, ++nj) {
        if(0 <= ni && nj <= n) {
          int sum = 0;
          for(int l=ni; l<i; ++l) {
            sum += a[l];
          }
          for(int r=j; r<nj; ++r) {
            sum += a[r];
          }
          chmax(sum, 0);
          chmax(dp[ni][nj], dp[i][j] + sum);
        }
      }
    }
  }

  for(int k=4; k<=n; ++k) {
    for(int i=0, j=k; j<=n; ++i, ++j) {
      for(int m=i+1; m<j; ++m) {
        chmax(dp[i][j], dp[i][m] + dp[m][j]);
      }
    }
  }

  cout << dp[0][n] << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}

Submission Info

Submission Time
Task B - Three Coins
User chiara_kyokkou
Language C++ (GCC 9.2.1)
Score 0
Code Size 1077 Byte
Status WA
Exec Time 46 ms
Memory 4232 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 3
AC × 5
WA × 44
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt WA 46 ms 4232 KB
001.txt WA 45 ms 4188 KB
002.txt WA 45 ms 4120 KB
003.txt WA 44 ms 4080 KB
004.txt WA 39 ms 4160 KB
005.txt WA 43 ms 4108 KB
006.txt WA 40 ms 4080 KB
007.txt WA 41 ms 4232 KB
008.txt WA 44 ms 4056 KB
009.txt WA 43 ms 4224 KB
010.txt WA 43 ms 4232 KB
011.txt WA 45 ms 4112 KB
012.txt WA 45 ms 4052 KB
013.txt WA 41 ms 4016 KB
014.txt WA 44 ms 4188 KB
015.txt WA 41 ms 4120 KB
016.txt WA 44 ms 4232 KB
017.txt WA 44 ms 4048 KB
018.txt WA 42 ms 4184 KB
019.txt WA 44 ms 4184 KB
020.txt WA 45 ms 4120 KB
021.txt WA 43 ms 4208 KB
022.txt WA 45 ms 4156 KB
023.txt WA 45 ms 4164 KB
024.txt WA 46 ms 4056 KB
025.txt WA 43 ms 4136 KB
026.txt WA 44 ms 4228 KB
027.txt WA 40 ms 4232 KB
028.txt WA 43 ms 4108 KB
029.txt WA 46 ms 4052 KB
030.txt WA 41 ms 4232 KB
031.txt WA 44 ms 4212 KB
032.txt WA 44 ms 4200 KB
033.txt WA 40 ms 4184 KB
034.txt WA 45 ms 4120 KB
035.txt AC 43 ms 4080 KB
036.txt WA 41 ms 4120 KB
037.txt WA 42 ms 4048 KB
038.txt WA 41 ms 4052 KB
039.txt WA 40 ms 4076 KB
040.txt WA 42 ms 4208 KB
041.txt WA 41 ms 4016 KB
042.txt WA 42 ms 4224 KB
043.txt WA 40 ms 4136 KB
044.txt WA 44 ms 4120 KB
045.txt AC 43 ms 4232 KB
example0.txt AC 2 ms 3544 KB
example1.txt AC 3 ms 3608 KB
example2.txt AC 2 ms 3488 KB