社区讨论
TLE,不知道为什么
UVA11475Extend to Palindrome参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @m07k8cjx
- 此快照首次捕获于
- 2024/08/24 11:07 2 年前
- 此快照最后确认于
- 2024/08/24 11:56 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
string s,t;
int n,m,a[200005];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
while(cin>>s){
n=s.length(),m=2*n+1;
t=" ";
for(int i=0;i<n;i++) t=t+s[i]+" ";
int l=0,r=0,x,ans=0;
for(int i=0;i<m;i++){
if(i>r) x=1;
else x=min(a[l+r-i],r-i+1);
while(i-x>=0&&i+x<m&&t[i-x]==t[i+x]) x++;
a[i]=x;
if(i+x==m) ans=max(ans,x-1);
if(i+x-1>r) l=i-x+1,r=i+x-1;
}
for(int i=n-ans-1;i>=0;i--) s.push_back(s[i]);
cout<<s<<"\n";
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...