Submission #1359850

#TimeUsernameProblemLanguageResultExecution timeMemory
1359850haykadamStove (JOI18_stove)C++20
20 / 100
1099 ms98564 KiB
// ....   ....       ...      ..     ..  ...   ..
// ....   ....      .. ..      ..   ..   ... ..
// ...........     ..   ..       ...     .....
// ...........    .........      ...     .....
// ....   ....   ..       ..     ...     ... ..
// ....   ....  ..         ..    ...     ...   ..

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <stack>
#include <map>
#include <queue>
#include <cstring>
#include <string>
#include <tuple>
#include <utility>
#define ll long long
#define endl "\n"
#define ld long double 
#define db double
#define rt return 0
#define FAST ios::sync_with_stdio(false);cin.tie(nullptr)
#define pb push_back
#define lb lower_bound 
#define ub upper_bound 
#define V vector 
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define D2 vector<vector<int>>
#define pq priority_queue
#define frop freopen("676776","r",stdin);freopen("676776","w",stdout);
#define itn int 
#define tin int 
#define pss pair<string,string>
#define all(x) x.begin(),x.end()
using namespace std;
ll gcd(ll a, ll b)
{
    if (a == 0 || b == 0) {
        return  max(a, b);
    }
    if (a <= b) {
        return gcd(a, b % a);
    }
    else {
        return gcd(a % b, b);
    }
}
const int ans = 1e9 + 7;
const int N = 5007;
int dp[N][N];
int main() {
    FAST;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = ans;
        }
    }
    int n, k;
    cin >> n >> k;
    vector<int>a(n + 1);
    cin >> a[1];
    dp[1][1] = 1;
    for (int i = 2; i <= n; i++) {
        cin >> a[i];
        dp[i][1] = a[i] - a[1] + 1;
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= min(i, k); j++) {
            for (int k1 = 1; k1 < i; k1++) {
                if (dp[k1][j - 1] != ans) {
                    dp[i][j] = min(dp[i][j], dp[k1][j - 1] + (a[i] - a[k1 + 1] + 1));
                }
            }
        }
    }
    cout << dp[n][k] << endl;
    rt;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...