# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1264602 | ducdev | Stove (JOI18_stove) | C++17 | 73 ms | 152900 KiB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e5;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
template <class X, class Y>
bool minimize(X &x, const Y &y) {
if (x <= y) return false;
x = y;
return true;
};
int n, k;
int a[MAX_N + 5];
namespace SUBTASK_12 {
const int K = 5000;
const int N = 5000;
ll dp[K + 5][N + 5][2];
void Solve() {
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j][0] = dp[i][j][1] = INF;
};
};
for (int i = 1; i <= n; i++) dp[1][i][1] = (a[i] + 1) - a[1];
for (int i = 2; i <= k; i++) {
for (int j = i; j <= n; j++) {
dp[i][j][1] = min(dp[i - 1][j - 1][1] + 1, dp[i][j - 1][0] + (a[j] + 1) - a[j - 1]);
dp[i][j][0] = min(dp[i - 1][j - 1][1], dp[i][j - 1][0] + a[j] - a[j - 1]);
};
};
cout << dp[k][n][1] << '\n';
};
}; // namespace SUBTASK_12
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
};
SUBTASK_12::Solve();
// SUBTASK_3::Solve();
};
컴파일 시 표준 에러 (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... |