# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
281816 | BeanZ | Stove (JOI18_stove) | C++14 | 102 ms | 153080 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
ll a[5005], dp[5005][5005][2];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("VietCT.INP", "r")){
freopen("VietCT.INP", "r", stdin);
freopen("VietCT.OUT", "w", stdout);
}
ll n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i <= n; i++){
for (int j = 0; j <= k; j++){
for (int x = 0; x < 2; x++){
dp[i][j][x] = 1e10;
}
}
}
dp[1][1][0] = 1;
dp[1][1][1] = 1;
for (int i = 2; i <= n; i++){
for (int j = 1; j <= min(1ll * i, k); j++){
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + a[i] - a[i - 1]);
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + a[i] - a[i - 1]);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][1] + 1);
}
}
ll ans = 1e18;
for (int i = 1; i <= k; i++){
ans = min(ans, dp[n][i][1]);
}
cout << ans;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |