QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#477276 | #323. Hills | litvinas | 0 | 0ms | 3764kb | C++20 | 2.6kb | 2024-07-14 00:58:23 | 2024-07-14 00:58:24 |
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
using ll = int64_t;
#define pb push_back
#define all(a) a.begin(),a.end()
#define ppi pair<pair<int,int>,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int int64_t
// xcode cant include bits/stdc++.h
using namespace std;
//ifstream fin ("sleepy.in");
//ofstream fout ("sleepy.out");
/* /\_/\
* (= ._.)
* / > \>
*/
// encouraging cat
const int INF = 10000000000000000;
const int mod = 1000000007;
int32_t main() {
int n;
cin >> n;
vector<int> a(n);
vector<vector<vector<int>>> dp(n,vector<vector<int>> (n,vector<int> (2,INF)));
for (int i = 0;i < n;i++)
{
cin >> a[i];
}
dp[0][0][0] = 0;
if (n > 1)
dp[0][1][1] = max((int)0,a[1] - a[0] + 1);
else
dp[0][1][1] = 0;
for (int i = 1;i < n;i++)
{
for (int k = 0;k <= i;k++)
{
if (k == 0)
{
dp[i][k][0] = dp[i - 1][k][0];
continue;
}
dp[i][k][0] = min(dp[i - 1][k][0],dp[i - 1][k][1]);
if (i < n - 1)
{
int next = max(a[i + 1] - a[i] + 1,(int)0);
dp[i][k][1] = dp[i - 1][k - 1][0] + max(a[i - 1] - a[i] + 1,(int)0) + next;
if (i >= 2)
{
int prev = max(a[i - 1] - a[i - 2] + 1,(int)0);
int add = abs(max(a[i - 1] - a[i] + 1,(int)0) - prev);
dp[i][k][1] = min(dp[i][k][1],dp[i - 2][k - 1][1] + add + next);
}
}
else
{
dp[i][k][1] = dp[i - 1][k - 1][0] + max(a[i - 1] - a[i] + 1,(int)0);
if (i >= 2)
{
int prev = max(a[i - 1] - a[i - 2] + 1,(int)0);
int add = abs(max(a[i - 1] - a[i] + 1,(int)0) - prev);
dp[i][k][1] = min(dp[i][k][1],dp[i - 2][k - 1][1] + add);
}
}
}
}
int x = n / 2;
if (n % 2)
x++;
for (int k = 1;k <= x;k++)
{
cout << min(dp[n - 1][k][0],dp[n - 1][k][1]) << " ";
}
cout << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 3764kb
input:
3 1 2 4
output:
0 2
result:
ok 2 number(s): "0 2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 3 2 1
output:
0 2
result:
ok 2 number(s): "0 2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
3 1 2 1
output:
0 2
result:
ok 2 number(s): "0 2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3 3 3 3
output:
1 1
result:
ok 2 number(s): "1 1"
Test #5:
score: -7
Wrong Answer
time: 0ms
memory: 3600kb
input:
3 50 80 80
output:
1 32
result:
wrong answer 2nd numbers differ - expected: '31', found: '32'
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%