UVALive 6439 -- Pasti Pas!
This is because it requires the longest text string. On the one hand, we walk forward from the past, on the other hand, when we get the same part for a whole, in this way, we can get the longest input string. then the problem is that if we judge whether the strings in the first and second parts of the enumeration are the same, we can also determine the brute force code, but this will definitely return timeout, so we use the string hash method to judge.
The Code is as follows:
#include
#include
#include
using namespace std;typedef unsigned long long ull;ull Hash[50500];char str[50500];int main(){ //freopen("in.txt","r",stdin); Hash[0]=1; for(int i=1;i<=50500;i++) Hash[i]=Hash[i-1]*31; int t,Case=0; scanf("%d",&t); while(t--) { scanf("%s",str); int l=0,r=strlen(str)-1; int ans=0,len=0; ull x=0,y=0; while(1) { if(l==r) { ans++; break; } if(l>r) { if(x||y) ans++; break; } if(x==0&&y==0&&str[l]==str[r]) { ans+=2; l++;r--; len=0; continue; } x=x*31+(str[l]-'A'); y+=Hash[len]*(str[r]-'A'); len++; if(x==y) { ans+=2; x=0,y=0,len=0; } l++; r--; } printf("Case #%d: %d\n",++Case,ans); } return 0;}