#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define all(x) x.begin()+1,x.end()
const int N = 4e5+1;
void solve() {
int n,d;
cin >> n >> d;
vi a(n+1);
F(i,n) cin >> a[i];
vi l(n+1);
int lst = 1;
F(i,n) {
l[i] = lst;
if (a[i]) lst = i;
}
int ans = 0;
int ptr = n;
while (ptr > 1) {
if (l[ptr] < ptr-d) {
ans++;
ptr=ptr-d;
}
else ptr = l[ptr];
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
13 ms |
4956 KB |
Output is correct |
9 |
Correct |
13 ms |
5468 KB |
Output is correct |
10 |
Correct |
14 ms |
4956 KB |
Output is correct |