求调
  • 板块学术版
  • 楼主Pollococido
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/29 22:09
  • 上次更新2025/1/30 18:04:59
查看原帖
求调
919410
Pollococido楼主2025/1/29 22:09

问题描述

{sn}(si[o,p])\{s_n\}(s_i \in [\texttt{o},\texttt{p}]) 中最长的所有出现的字符的数量相等的子串长度。

35pts 代码

不知道为啥错。

#include <bits/stdc++.h>
using namespace std;
long long n, maxx = -0x3f3f3f3f;
long long a[200010], sum[200010];
char c;
map<int, long long> Mp;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> c;
        if (c == 'l') a[i] = 1;
        else if (c == 'r') a[i] = -1;
    }
    for (int i = 1; i <= n + 1; i++) {
        sum[i + 1] = sum[i] + a[i];
    }
    for (int i = 1; i <= n + 1; i++) {
        if (Mp[sum[i]]) maxx = max(maxx, i - Mp[sum[i]]);
        else Mp[sum[i]] = i;
    }
    cout << maxx;
    return 0;
}
2025/1/29 22:09
加载中...