QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#528642 | #323. Hills | Nevll | 0 | 0ms | 4100kb | C++14 | 1.7kb | 2024-08-23 18:15:01 | 2024-08-23 18:15:04 |
answer
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
# define pii pair<int, int>
using namespace std;
ll dp[3][5001][2];
int main() {
int N;
scanf("%d", &N);
vector<ll> arr(N + 2);
for(int i=1;i<=N;i++) scanf("%lld", &arr[i]);
arr[0] = arr[N + 1] = -1;
for(int i=0;i<=N;i++) {
for(int k=0;k<3;k++) {
for(int c=0;c<2;c++) {
dp[k][i][c] = 1e18;
}
}
}
dp[2][0][0] = 0ll;
for(int i=1;i<=N+1;i++) {
for(int c=0;c<=N;c++) {
for(int d=0;d<2;d++) {
dp[0][c][d] = dp[1][c][d];
dp[1][c][d] = dp[2][c][d];
dp[2][c][d] = 1e18;
}
}
for(int c=0;c<=N;c++) {
for(int d=0;d<2;d++) {
dp[2][c][d] = min(dp[2][c][d], min(dp[1][c][0], dp[1][c][1]));
}
}
if(i >= 2) {
for(int c=0;c<N;c++) {
if(dp[0][c][0] != 1e18) {
ll val = max(0ll, arr[i - 2] - arr[i - 1] + 1ll);
ll val1 = max(0ll, arr[i] - arr[i - 1] + 1ll);
if(val1 > 0ll) dp[2][c + 1][1] = min(dp[2][c + 1][1], val + val1 + dp[0][c][0]);
else dp[2][c + 1][1] = min(dp[2][c + 1][1], val + val1 + dp[0][c][0]);
}
if(dp[0][c][1] != 1e18) {
ll val = max(0ll, arr[i - 3] - arr[i - 1]);
ll val1 = max(0ll, arr[i] - arr[i - 1] + 1ll);
// if(c == 1) cout<<"there "<<c<<" "<<i<<" "<<val<<" "<<val1<<endl;
if(val1 > 0ll) dp[2][c + 1][1] = min(dp[2][c + 1][1], val + val1 + dp[0][c][1]);
else dp[2][c + 1][1] = min(dp[2][c + 1][1], val + val1 + dp[0][c][1]);
// cout<<c + 1<<" "<<dp[2][c + 1][1]<<endl;
}
}
}
// cout<<"dp : "<<dp[2][1][1]<<" "<<dp[2][2][0]<<endl;
}
for(int i=1;i<=(N + 1)/2;i++) printf("%lld ", min(dp[2][i][0], dp[2][i][1]));
printf("\n");
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 4100kb
input:
3 1 2 4
output:
0 2
result:
ok 2 number(s): "0 2"
Test #2:
score: 7
Accepted
time: 0ms
memory: 3824kb
input:
3 3 2 1
output:
0 2
result:
ok 2 number(s): "0 2"
Test #3:
score: 7
Accepted
time: 0ms
memory: 3772kb
input:
3 1 2 1
output:
0 2
result:
ok 2 number(s): "0 2"
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3844kb
input:
3 3 3 3
output:
0 1
result:
wrong answer 1st numbers differ - expected: '1', found: '0'
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%