QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282012 | #323. Hills | A_programmer | 0 | 1ms | 3556kb | C++14 | 814b | 2023-12-11 10:05:34 | 2023-12-11 10:05:36 |
answer
#include <bits/stdc++.h>
using namespace std;
int dp[2505][3], dp_n[2505][3];
int a[5005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
a[0] = a[n + 1] = -1e9;
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++)
{
memset(dp_n, 0x3f, sizeof(dp_n));
for (int k = 0; k <= (i + 1) / 2; k++)
{
dp_n[k][0] = min(dp_n[k][0], min(dp[k][0], dp[k][1]));
dp_n[k][1] = min(dp_n[k][1], dp[k][2] + max(0, a[i] - a[i - 1] + 1));
if (k) dp_n[k][2] = min(dp_n[k][2], min(dp[k - 1][0], dp[k - 1][1]) + max(0, a[i - 1] - a[i] + 1));
}
memcpy(dp, dp_n, sizeof(dp_n));
}
for (int k = 1; k <= (n + 1) / 2; k++) cout << min(dp[k][0], min(dp[k][1], dp[k][2])) << " ";
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 3556kb
input:
3 1 2 4
output:
0 2
result:
ok 2 number(s): "0 2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
3 3 2 1
output:
0 2
result:
ok 2 number(s): "0 2"
Test #3:
score: -7
Wrong Answer
time: 0ms
memory: 3452kb
input:
3 1 2 1
output:
0 4
result:
wrong answer 2nd numbers differ - expected: '2', found: '4'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%