前缀和+n^2奇葩AC代码,数据雀食水
查看原帖
前缀和+n^2奇葩AC代码,数据雀食水
933264
cyLLxGP70ytRvxZTZs3f楼主2024/9/23 21:44
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define inf 0x3f3f3f3f
#define sinf 0x80808080
const int N = 1e6 + 5;
string s;
int a[N], sum[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    int l = s.size();
    int maxn = 0;
    for (int i = 0; i < l; i++)
        a[i + 1] = (s[i] == 'G' ? 1 : 0);
    for (int i = 1; i <= l; i++)
        sum[i] = sum[i - 1] + a[i];
    for (int i = 1; i <= l; i++)
    {
        for (int j = i; j <= l; j++)
        {
            double tmp = (j - i + 1.0) / 2;
            if (sum[j] - sum[i - 1] == tmp)
                maxn = max(maxn, j - i + 1);
        }
    }
    cout << maxn << '\n';
    return 0;
}
2024/9/23 21:44
加载中...