Submission #637002

# Submission time Handle Problem Language Result Execution time Memory
637002 2022-08-31T04:32:10 Z bonk Stove (JOI18_stove) C++14
20 / 100
1000 ms 196176 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 5002;
ll dp[N][N], a[N];
int n, k;

ll f(int idx, int k){
    if(k < 0) return 1e18;
    if(idx > n) return 0;
    ll &cur = dp[idx][k];

    if(cur != -1) return cur;

    cur = 1e18;

    for(int i = idx; i <= n; i++){
        cur = min(cur, f(i + 1, k - 1) + a[i] - a[idx] + 1);
    }

    return cur;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(dp, -1, sizeof(dp));

    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    cout << f(1, k) << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 196072 KB Output is correct
2 Correct 69 ms 196124 KB Output is correct
3 Correct 69 ms 196080 KB Output is correct
4 Correct 70 ms 196096 KB Output is correct
5 Correct 70 ms 196044 KB Output is correct
6 Correct 71 ms 196052 KB Output is correct
7 Correct 71 ms 196044 KB Output is correct
8 Correct 72 ms 196108 KB Output is correct
9 Correct 67 ms 196040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 196072 KB Output is correct
2 Correct 69 ms 196124 KB Output is correct
3 Correct 69 ms 196080 KB Output is correct
4 Correct 70 ms 196096 KB Output is correct
5 Correct 70 ms 196044 KB Output is correct
6 Correct 71 ms 196052 KB Output is correct
7 Correct 71 ms 196044 KB Output is correct
8 Correct 72 ms 196108 KB Output is correct
9 Correct 67 ms 196040 KB Output is correct
10 Correct 382 ms 196176 KB Output is correct
11 Execution timed out 1093 ms 196172 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 196072 KB Output is correct
2 Correct 69 ms 196124 KB Output is correct
3 Correct 69 ms 196080 KB Output is correct
4 Correct 70 ms 196096 KB Output is correct
5 Correct 70 ms 196044 KB Output is correct
6 Correct 71 ms 196052 KB Output is correct
7 Correct 71 ms 196044 KB Output is correct
8 Correct 72 ms 196108 KB Output is correct
9 Correct 67 ms 196040 KB Output is correct
10 Correct 382 ms 196176 KB Output is correct
11 Execution timed out 1093 ms 196172 KB Time limit exceeded
12 Halted 0 ms 0 KB -