QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#670437 | #7067. The Great Wall | Soestx | WA | 1ms | 4012kb | C++23 | 1.2kb | 2024-10-23 21:43:19 | 2024-10-23 21:43:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pll pair<int,int>
#define fi first
#define se second
typedef long long LL;
typedef unsigned long long ull;
int n, m, k;
const int N = 1e4 + 10, M = 1e7 + 10, mod = 998244353;
const double eps = 1e-6, inf = 1e8;
int dp[2][N][4];
int num[N];
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>num[i];
memset(dp,-0x3f,sizeof dp);
dp[1][0][3]=0;
int idx=1;
for(int i=1;i<=n;i++)
{
idx^=1;
for(int j=1;j<=i;j++)
{
dp[idx][j][0]=dp[idx^1][j-1][3];
dp[idx][j][1]=dp[idx^1][j-1][3]-num[i];
dp[idx][j][2]=dp[idx^1][j-1][3]+num[i];
dp[idx][i][3]=dp[idx^1][j-1][3];
dp[idx][j][0]=max(dp[idx][j][0],dp[idx^1][j][0]);
dp[idx][j][1]=max({dp[idx][j][1],dp[idx^1][j][1],dp[idx^1][j][0]-num[i]});
dp[idx][j][2]=max({dp[idx][j][2],dp[idx^1][j][2],dp[idx^1][j][0]+num[i]});
dp[idx][j][3]=max({dp[idx][j][3],dp[idx^1][j][3],dp[idx^1][j][1]+num[i],dp[idx^1][j][2]-num[i]});
}
}
for(int i=1;i<=n;i++) cout<<dp[idx][i][3]<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
//cin>>T;
while (T--) {
solve();
}
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3980kb
input:
5 1 2 3 4 5
output:
4 3 2 1 0
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
5 1 2 1 2 1
output:
1 2 2 1 0
result:
ok 5 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3952kb
input:
6 1 1 4 5 1 4
output:
4 7 7 4 3 0
result:
wrong answer 4th lines differ - expected: '7', found: '4'