QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370941 | #7067. The Great Wall | AntyO | ML | 0ms | 0kb | C++14 | 846b | 2024-03-29 19:56:01 | 2024-03-29 19:56:01 |
answer
#include <bits/stdc++.h>
#define ll long long
const int MAX=1e4+10;
int n, dp[MAX][MAX][4], a[MAX];
using std::max;
int main() {
scanf("%d", &n);
for (int i=1;i<=n;i++) scanf("%d", &a[i]);
memset(dp, -0x3f, sizeof(dp));
dp[0][0][3]=0;
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) {
dp[i][j][0]=max(dp[i-1][j-1][3], dp[i-1][j][0]);
dp[i][j][1]=max({dp[i-1][j-1][3]+a[i], dp[i-1][j][0]+a[i], dp[i-1][j][1]});
dp[i][j][2]=max({dp[i-1][j-1][3]-a[i], dp[i-1][j][0]-a[i], dp[i-1][j][2]});
dp[i][j][3]=max({dp[i-1][j-1][3], dp[i-1][j][3], dp[i-1][j][1]-a[i], dp[i-1][j][2]+a[i]});
}
// for (int i=1;i<=n;i++) {
// for (int j=1;j<=n;j++) {
// for (int k=0;k<=3;k++) printf("%d!", dp[i][j][k]);
// puts("\n===");
// }
// putchar('\n');
// }
for (int i=1;i<=n;i++) printf("%d\n", dp[n][i][3]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
5 1 2 3 4 5
output:
4 3 2 1 0