求助,二十分
查看原帖
求助,二十分
738168
wang0728楼主2024/8/7 21:34

桶做法

#include <bits/stdc++.h>
using namespace std;
int k,n;
bool a[10005];
long long ans;
bool look(int x){
	int l=x,r=x;
	while(l>=0 && r<=k){
		if(a[l]^a[r]!=0) return false;
		l--;
		r++;
	}
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		int s; cin>>s;
		a[s]=true;
	}
	for(int i=1;i<=k-1;i++){
		if(look(i)==true){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}
2024/8/7 21:34
加载中...