求大佬帮看一下,有两个样例过不去
查看原帖
求大佬帮看一下,有两个样例过不去
1122916
BLACK11楼主2024/4/11 17:23
#include <bits/stdc++.h>
#define FAST ios::sync_with_stdio(false);cin.tie(nullptr)
#define ft first
#define sd second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int MN=5*1e4+50;
const int inf=0x3f3f3f3f;
int a[MN],s[MN];
int c[15],pos[15];
inline void solve(){
	int N;
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> a[i];
		s[i]=s[i-1]+a[i];
	}
	memset(pos,-1,sizeof pos);
	pos[0]=0;
	int mx=0;
	for(int i=1;i<=N;i++){
		s[i]=s[i]%7;
	    if(pos[s[i]]==-1) pos[s[i]]=i;  //记录每个余数第一次出现的位置
		c[s[i]]=i-pos[s[i]]; //更新每个余数对应的最大长度
		//mx=max(mx,i-pos[s[i]]);
	}
	//cout << pos[0] << ' '<< pos[1] <<' ' << pos[4] << '\n';
	cout << *max_element(c,c+7);
	//cout << mx;
	return;
}
int main() {
	FAST;
//	int t;
//	cin >> t;
//	while (t--) {
		solve();
//	}
}

2024/4/11 17:23
加载中...