AC了,求关注
2024-06-30 10:46:50
发布于:浙江
6阅读
0回复
0点赞
#include <iostream>
using namespace std;
const int N = 1e5+5;
int prevnum[N];
int main()
{
int n, num;
int maxLength = 0;
cin >> n;
for ( int i = 1; i <= n; ++i ) {
cin >> num;
prevnum[i] = prevnum[i-1] + num;
}
for ( int i = 1; i <= n; ++i ) {
int j;
if ( !maxLength ) j = i+1;//maxLength没有被更新过,就从区间长度2开始
else j = i + maxLength - 1;
for ( ; j <= n; j += 2 ) {
//区间长度的一半 == 区间和
if ( (j-i+1)/2 == prevnum[j]-prevnum[i-1] ) {
maxLength = max(maxLength, j-i+1);
}
}
}
cout << maxLength << '\n';
return 0;
}
这里空空如也
有帮助,赞一个