Demo entry 6763352

mid

   

Submitted by 反对法 on Oct 22, 2018 at 03:40
Language: C++. Code size: 569 Bytes.

#include <bits/stdc++.h>

using namespace std;

const int N=1100;
const int inf=0x3f3f3f3f;
int a[N],b[N];
int main(){
	int n,r;
	scanf("%d%d",&n,&r);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=n;++i)
		if(a[i]==1)b[++cnt]=i;
	b[0]=-r+1;//区域[,0]
	b[cnt+1]=n+r;//区域[n+1,]
	int ans=0;
	int pre=0;
	//cout<<cnt<<endl;
	for(int i=1;i<=cnt;++i){
		if(b[i]-b[pre]>=2*r){ans=-1;break;}
		if(b[i+1]-b[pre]<2*r)continue;
		else {
			++ans;
			pre=i;
		}
	}
	if(!cnt||b[pre]+r-1<n)ans=-1;
	cout<<ans<<endl;
	return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).