90pts wa on #4 求助

P2697 宝石串

T1anBooy @ 2024-10-10 20:37:05

求大佬帮忙,90pts wa on #4

评测记录

#include <bits/stdc++.h>

#define F(A, B) for (int i = A; i <= B; i ++)
#define int long long

using namespace std;

const int N = 1e6+10;

 int f[2*N]; //记忆化 

signed main () {
    char ch;
    int sum = (int)1e6+5, cnt, ans = 0;
    string s;
    cin>>s;
    int l=s.length();
    F(1, l) {
        if (s[i-1] == 'R') sum ++;
        else sum --;
        if (sum == (int)1e6+5) ans = max(ans, abs(i - f[sum]));
        else f[sum]= i;
    }
    cout << ans;
    return 0;
}

by niuniudundun @ 2024-10-27 13:50:24

@T1anBooy

这题前缀和可以过,不用记忆化。


by T1anBooy @ 2024-11-11 18:20:56

@niuniudundun thx%%%


|