#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<int> v;
vector<vector<int>> dp;
int f(int i,int pos){
if(i == n){
return 0;
}
if(dp[i][pos] != -1)return dp[i][pos];
if(v[i] > pos+m){
dp[i][pos] = f(i+1,pos+m) + 1;
}else if(v[i] < pos+m){
dp[i][pos] = min(f(i+1,v[i]),f(i+1,pos+m)+1);
}else{
dp[i][pos] = f(i+1,v[i]);
}
return dp[i][pos];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
v.resize(n);
for(int i=0; i<n; i++){
cin >> v[i];
}
/*
int pos = 0;
int cont = 0;
for(int i=0; i<n; i++){
if(v[i] > pos+m){
cont++;
pos+=m;
}else pos = v[i];
}
cout << cont << endl;
*/
dp.assign(n,vector<int> (10000,-1));
cout << f(0,0) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
0 ms |
724 KB |
Output is correct |
6 |
Correct |
0 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
0 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
732 KB |
Output is correct |
16 |
Correct |
0 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
0 ms |
724 KB |
Output is correct |
6 |
Correct |
0 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
0 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
732 KB |
Output is correct |
16 |
Correct |
0 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
262 ms |
159100 KB |
Output is correct |
21 |
Correct |
191 ms |
196492 KB |
Output is correct |
22 |
Correct |
76 ms |
196408 KB |
Output is correct |
23 |
Incorrect |
282 ms |
196504 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
262 ms |
159100 KB |
Output is correct |
5 |
Correct |
191 ms |
196492 KB |
Output is correct |
6 |
Correct |
76 ms |
196408 KB |
Output is correct |
7 |
Incorrect |
282 ms |
196504 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
262 ms |
159100 KB |
Output is correct |
5 |
Correct |
191 ms |
196492 KB |
Output is correct |
6 |
Correct |
76 ms |
196408 KB |
Output is correct |
7 |
Incorrect |
282 ms |
196504 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |