标签:let style desc using tput auth win multiple tle
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3314 Accepted Submission(s): 1101
//在manachar的基础上,枚举回文串的中心,再找第三部分。 #include<cstdio> #include<cstring> #include<iostream> using namespace std; int read(){ register int x=0;bool f=1; register char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=0;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return f?x:-x; } const int N=3e5+10; int n,ans,cas,l,T,s[N],S[N],p[N]; void manacher(){ int id=0,mx=-1; for(int i=1;i<l;i++){ if(id+mx>i) p[i]=min(p[id*2-i],id+mx-i); while(i-p[i]>=0&&i+p[i]<=l&&S[i-p[i]]==S[i+p[i]]) p[i]++; if(id+mx<i+p[i]) id=i,mx=p[i]; } } void init(){ l=0;memset(p,0,sizeof p); for(int i=0;i<n;i++) S[++l]=-1,S[++l]=s[i]; S[++l]=-1; } int main(){ for(T=read(),cas=1;ans=0,cas<=T;cas++){ n=read(); for(int i=0;i<n;i++) s[i]=read(); init();manacher(); for(int i=1;i<=n*2+1;i+=2){ for(int j=i+p[i]-1;j-i>ans;j-=2){ if(j-i+1<=p[j]){ ans=max(ans,j-i); break; } } } printf("Case #%d: %d\n",cas,ans/2*3); } return 0; }
标签:let style desc using tput auth win multiple tle
原文地址:http://www.cnblogs.com/shenben/p/6253249.html