#include <bits/stdc++.h>
using namespace std;
int A[300005];
int main(){
int n,d;cin >> n >> d;
for(int i=1;i<=n;i++)cin >> A[i];
int maxi = 1, cnt = 0;
for(int i=2;i<=n;i++){
if(i > maxi + d)maxi = i - 1, cnt++;
if(A[i])maxi = i;
}
cout << cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
39 ms |
1960 KB |
Output is correct |
9 |
Correct |
40 ms |
2032 KB |
Output is correct |
10 |
Correct |
42 ms |
2028 KB |
Output is correct |