# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930611 |
2024-02-20T07:54:34 Z |
ArgoCahaya |
Stove (JOI18_stove) |
C++14 |
|
1000 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
int n, k;
int a[5005];
int dp[5005][5005][2];
int 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;
}
}
int &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 |
43 ms |
196436 KB |
Output is correct |
2 |
Correct |
35 ms |
196444 KB |
Output is correct |
3 |
Correct |
36 ms |
196436 KB |
Output is correct |
4 |
Correct |
34 ms |
196464 KB |
Output is correct |
5 |
Correct |
36 ms |
196436 KB |
Output is correct |
6 |
Correct |
35 ms |
196312 KB |
Output is correct |
7 |
Correct |
35 ms |
196436 KB |
Output is correct |
8 |
Correct |
34 ms |
196452 KB |
Output is correct |
9 |
Correct |
35 ms |
196440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
196436 KB |
Output is correct |
2 |
Correct |
35 ms |
196444 KB |
Output is correct |
3 |
Correct |
36 ms |
196436 KB |
Output is correct |
4 |
Correct |
34 ms |
196464 KB |
Output is correct |
5 |
Correct |
36 ms |
196436 KB |
Output is correct |
6 |
Correct |
35 ms |
196312 KB |
Output is correct |
7 |
Correct |
35 ms |
196436 KB |
Output is correct |
8 |
Correct |
34 ms |
196452 KB |
Output is correct |
9 |
Correct |
35 ms |
196440 KB |
Output is correct |
10 |
Correct |
36 ms |
196580 KB |
Output is correct |
11 |
Correct |
43 ms |
196692 KB |
Output is correct |
12 |
Correct |
98 ms |
196740 KB |
Output is correct |
13 |
Correct |
134 ms |
196944 KB |
Output is correct |
14 |
Correct |
137 ms |
196688 KB |
Output is correct |
15 |
Correct |
136 ms |
196692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
196436 KB |
Output is correct |
2 |
Correct |
35 ms |
196444 KB |
Output is correct |
3 |
Correct |
36 ms |
196436 KB |
Output is correct |
4 |
Correct |
34 ms |
196464 KB |
Output is correct |
5 |
Correct |
36 ms |
196436 KB |
Output is correct |
6 |
Correct |
35 ms |
196312 KB |
Output is correct |
7 |
Correct |
35 ms |
196436 KB |
Output is correct |
8 |
Correct |
34 ms |
196452 KB |
Output is correct |
9 |
Correct |
35 ms |
196440 KB |
Output is correct |
10 |
Correct |
36 ms |
196580 KB |
Output is correct |
11 |
Correct |
43 ms |
196692 KB |
Output is correct |
12 |
Correct |
98 ms |
196740 KB |
Output is correct |
13 |
Correct |
134 ms |
196944 KB |
Output is correct |
14 |
Correct |
137 ms |
196688 KB |
Output is correct |
15 |
Correct |
136 ms |
196692 KB |
Output is correct |
16 |
Execution timed out |
2298 ms |
262144 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |