标签:inpu max for mamicode ++ long image algorithm fine
#include <iostream> #include <algorithm> # define LL long long using namespace std; const int maxn=11000002; char data[maxn<<1]; int len[maxn<<1]; int idx; void input(){ idx=0; data[idx++]=‘#‘; char c=getchar(); while(c<‘a‘ || c>‘z‘) c=getchar(); while(c>=‘a‘ && c<=‘z‘){ data[idx++]=c; data[idx++]=‘#‘; c=getchar(); } idx--; } int main(){ input(); int mid=0; int rb=0; int res=0; for(int i=1;i<=idx;i++){ if(i<rb){ len[i]=min(rb-i,len[2*mid-i]); } while(i-len[i]>=0 && i+len[i]<=idx && data[i-len[i]]==data[i+len[i]]){ len[i]++; } len[i]--; res=max(res,len[i]); if(i+len[i]>rb){ mid=i; rb=i+len[i]; } } printf("%d", res); return 0; }
标签:inpu max for mamicode ++ long image algorithm fine
原文地址:https://www.cnblogs.com/FEIIEF/p/12494387.html