why
  • 板块P2843 暗杀
  • 楼主jypo
  • 当前回复5
  • 已保存回复5
  • 发布时间2025/7/28 14:56
  • 上次更新2025/7/28 17:48:51
查看原帖
why
992989
jypo楼主2025/7/28 14:56
#include<bits/stdc++.h>
using namespace std;
int n,k,a[100005][35];
bool check(int x){
	for(int l=1;l+x-1<=n;++l){
		bool f=1;
		int r=l+x-1,s=a[r][1]-a[l-1][1];
		for(int j=2;j<=k;++j){
			if(a[r][j]-a[l-1][j]!=s){
				f=0;
				break;
			}
		}
		if(f) return 1;
	}
	return 0;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		string s="";
		while(x){
			s+=x%2+'0';
			x/=2;
		}
		s=" "+s;
		while(s.size()<=k) s=s+'0';
		for(int j=1;j<=k;++j){
			a[i][j]=s[j]-'0';
			a[i][j]+=a[i-1][j];
		}
	}
//	for(int i=1;i<=n;++i){
//		for(int j=1;j<=k;++j){
//			cout<<a[i][j]<<' ';
//		}
//		cout<<endl;
//	}
	int l=0,r=n;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)) l=mid+1;
		else r=mid-1;
	}
	if(l==0) cout<<0;
	else cout<<l-1;
	return 0;
}

二分70pts求调

2025/7/28 14:56
加载中...