【全RE求助】
查看原帖
【全RE求助】
250357
呐呐呐楼主2022/3/15 16:34

本机跑的小样例都过了,不知道为啥会RE

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 10 ;
char str[maxn] , s[maxn] ;
int cnt , n , m , p[maxn] ;
void manacher()
{
    int rt = 0 , mid = 0 ;
    int res = 0 ;
    for(int i = 1 ; i <= m ; i ++)
    {
        if(i < rt) 
        {
            p[i] = min(p[2 * mid - i ] , rt - i ) ;
            while(str[i + p[i]] == str[i - p[i]]) p[i] ++ ;
        }
        else{
            p[i] = 1 ;
            while(str[i + p[i]] == str[i - p[i]]) p[i] ++ ;
        }
        if(i + p[i] > rt)
        {
            rt = i + p[i] ;
            mid = i ;
        }
        res = max(res , p[i] - 1) ;
    }
    cout << res << endl;
}


int main()
{
    cin >> s ;
    str[0] = '!' , str[1] = '#' ;
    n =  strlen(s) ;
    for(int i = 0 ; i < n ; i ++)
    {
        str[i * 2 + 2] = s[i] ;
        str[i * 2 + 3] = '#' ;
    }
    m = n * 2 + 1 ;
    str[n * 2 + 2] = '@' ;
    manacher() ;


    return 0 ;
}
2022/3/15 16:34
加载中...