# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930146 |
2024-02-18T17:04:20 Z |
takeonicky |
Stove (JOI18_stove) |
C++14 |
|
41 ms |
80620 KB |
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3;
const long long INF = 1e15;
int n, k;
int a[MAXN+5];
long long dp[MAXN+5][MAXN+5][5];
long long f(int idx, int cnt, int state){
if(cnt > k) return INF;
if(idx == n){
if(state == 1) return 0;
else{
if(cnt < k) return 1;
return INF;
}
}
long long &ret = dp[idx][cnt][state];
if(ret != -1) return ret;
ret = INF;
if(state){
ret = min(ret, f(idx+1, cnt, 1) + (a[idx+1]-a[idx]));
ret = min(ret, f(idx+1, cnt, 0) + (a[idx+1]-a[idx]));
}
else{
ret = min(ret, f(idx+1, cnt+1, 1) + 1);
ret = min(ret, f(idx+1, cnt+1, 0) + 1);
}
return ret;
}
int main(){
memset(dp, -1, sizeof(dp));
cin>>n>>k;
for(int i=1; i<=n; i++){
cin>>a[i];
}
cout<<f(0,0,0)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39768 KB |
Output is correct |
2 |
Correct |
6 ms |
39772 KB |
Output is correct |
3 |
Correct |
7 ms |
39772 KB |
Output is correct |
4 |
Correct |
6 ms |
39772 KB |
Output is correct |
5 |
Correct |
6 ms |
39772 KB |
Output is correct |
6 |
Correct |
6 ms |
39768 KB |
Output is correct |
7 |
Correct |
6 ms |
39772 KB |
Output is correct |
8 |
Correct |
6 ms |
39840 KB |
Output is correct |
9 |
Correct |
6 ms |
39772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39768 KB |
Output is correct |
2 |
Correct |
6 ms |
39772 KB |
Output is correct |
3 |
Correct |
7 ms |
39772 KB |
Output is correct |
4 |
Correct |
6 ms |
39772 KB |
Output is correct |
5 |
Correct |
6 ms |
39772 KB |
Output is correct |
6 |
Correct |
6 ms |
39768 KB |
Output is correct |
7 |
Correct |
6 ms |
39772 KB |
Output is correct |
8 |
Correct |
6 ms |
39840 KB |
Output is correct |
9 |
Correct |
6 ms |
39772 KB |
Output is correct |
10 |
Runtime error |
41 ms |
80620 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39768 KB |
Output is correct |
2 |
Correct |
6 ms |
39772 KB |
Output is correct |
3 |
Correct |
7 ms |
39772 KB |
Output is correct |
4 |
Correct |
6 ms |
39772 KB |
Output is correct |
5 |
Correct |
6 ms |
39772 KB |
Output is correct |
6 |
Correct |
6 ms |
39768 KB |
Output is correct |
7 |
Correct |
6 ms |
39772 KB |
Output is correct |
8 |
Correct |
6 ms |
39840 KB |
Output is correct |
9 |
Correct |
6 ms |
39772 KB |
Output is correct |
10 |
Runtime error |
41 ms |
80620 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |