#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n, d; cin>>n>>d;
vector<int> a(n);
for(int i=0; i<n; i++) cin>>a[i];
int k=0, ans=0;
for(int i=0; i<n; i++)
{
if(i==k&&a[i]==1)
{
k=i+d;
}
else if(i==k)
{
ans++;
k=i+d;
}
else if(a[i]==1)
{
k=i+d;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
14 ms |
2644 KB |
Output is correct |
9 |
Correct |
20 ms |
2644 KB |
Output is correct |
10 |
Correct |
13 ms |
2644 KB |
Output is correct |