manacher 76pts求调(玄关

P4287 [SHOI2011] 双倍回文

huta0 @ 2024-03-15 19:33:41

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
#include<unordered_map>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define drep(a,b,c) for(int a=b;a>=c;a--)
#define a_all a.begin(),a.end()
using namespace std;
typedef long long ll;
const int N = 5e5+5;
int h[N<<1],n,top;
char tmp[N<<1],s[N<<1];
int fd;
inline void manacher() {
    int r=0,md=1;
    rep(i,1,top-1) {
        h[i]=i<=r?min(h[(md<<1)-i],r-i):1;
        while(tmp[i-h[i]]==tmp[i+h[i]]) h[i]++;
        if(h[i]+i>r) {
             r=h[i]+i,md=i;
             if((h[i]-1)%4==0&&2*((h[(i-((h[i])>>1))]-1))==h[i]-1) fd=max(fd,h[i]-1);
        }
    }
}
inline void sol() {
    tmp[0]='-';
    tmp[++top]='$';
    int p=strlen(s);
    rep(i,0,p-1) {
        tmp[++top]=s[i],tmp[++top]='$';
    }
}
signed main() {
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    cin>>s;
    sol();
    manacher();
    cout<<fd<<endl;
    return 0;
}

by MC_OIer @ 2024-07-26 21:05:30

Me too 76pts WA on #1,3,8


|