Contest Duration: - (local time) (210 minutes) Back to Home

Submission #19707406

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); }
template<typename T1, typename T2> inline bool chmin(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<int> sum(n+1);
sum[0] = 0;
for(int i=0; i<n; ++i) {
sum[i+1] = sum[i] + a[i];
}

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

for(int k=3; k<=n; ++k) {
for(int i=0, j=k; j<=n; ++i, ++j) {
for(int m=i+1; m<j; ++m) {
chmax(dpmax[i][j], dpmax[i][m] + dpmax[m][j]);
chmin(dpmin[i][j], dpmin[i][m] + dpmin[m][j]);
}
chmax(dpmax[i][j], max(dpmax[i+1][j], dpmax[i][j-1]));
chmin(dpmin[i][j], min(dpmin[i+1][j], dpmin[i][j-1]));

if(!(k % 3)) {
for(int ni=i, nj=j-3; nj<=j; ++ni, ++nj) {
int sum = 0;
for(int l=i; l<ni; ++l) {
sum += a[l];
}
for(int r=nj; r<j; ++r) {
sum += a[r];
}
chmax(dpmax[i][j], dpmax[ni][nj] + max(sum, 0));
chmin(dpmin[i][j], dpmin[ni][nj] + min(sum, 0));
}
chmax(dpmax[i][j], sum[j] - sum[i] - dpmin[i][j]);
chmin(dpmin[i][j], sum[j] - sum[i] - dpmax[i][j]);
}
}
}

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

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

#### Submission Info

Submission Time 2021-01-26 20:48:29+0900 B - Three Coins chiara_kyokkou C++ (GCC 9.2.1) 800 1613 Byte AC 71 ms 5228 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
 AC × 3
 AC × 49
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 AC 70 ms 5224 KB
001.txt AC 66 ms 5100 KB
002.txt AC 67 ms 5144 KB
003.txt AC 67 ms 5228 KB
004.txt AC 70 ms 5228 KB
005.txt AC 67 ms 5224 KB
006.txt AC 68 ms 5220 KB
007.txt AC 69 ms 5172 KB
008.txt AC 68 ms 5156 KB
009.txt AC 70 ms 5224 KB
010.txt AC 68 ms 5088 KB
011.txt AC 68 ms 5156 KB
012.txt AC 66 ms 5072 KB
013.txt AC 68 ms 5040 KB
014.txt AC 70 ms 5172 KB
015.txt AC 66 ms 5112 KB
016.txt AC 68 ms 5088 KB
017.txt AC 69 ms 5072 KB
018.txt AC 68 ms 5156 KB
019.txt AC 69 ms 5176 KB
020.txt AC 71 ms 5164 KB
021.txt AC 66 ms 5104 KB
022.txt AC 68 ms 5156 KB
023.txt AC 70 ms 5104 KB
024.txt AC 67 ms 5156 KB
025.txt AC 69 ms 5104 KB
026.txt AC 68 ms 5176 KB
027.txt AC 68 ms 5088 KB
028.txt AC 67 ms 5160 KB
029.txt AC 69 ms 5104 KB
030.txt AC 68 ms 5104 KB
031.txt AC 66 ms 5044 KB
032.txt AC 67 ms 5160 KB
033.txt AC 69 ms 5172 KB
034.txt AC 65 ms 5220 KB
035.txt AC 66 ms 5040 KB
036.txt AC 68 ms 5100 KB
037.txt AC 65 ms 5176 KB
038.txt AC 68 ms 5160 KB
039.txt AC 69 ms 5112 KB
040.txt AC 66 ms 5084 KB
041.txt AC 68 ms 5176 KB
042.txt AC 69 ms 5156 KB
043.txt AC 65 ms 5164 KB
044.txt AC 68 ms 5088 KB
045.txt AC 64 ms 5076 KB
example0.txt AC 3 ms 3532 KB
example1.txt AC 2 ms 3420 KB
example2.txt AC 4 ms 3364 KB