首页 > 代码库 > Ural 2040 Palindromes and Super Abilities 2

Ural 2040 Palindromes and Super Abilities 2

题目太坑,发一波纪念一下

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N=5000010;
 5 struct PAM{
 6     int cnt,last;
 7     int a[N][2],l[N],f[N];
 8     char s[N];
 9     PAM(){
10         cnt=f[0]=f[1]=1;
11         l[1]=-1;
12     }
13     int get_fail(int x,int loc){
14         while(s[loc-l[x]-1]!=s[loc])x=f[x];
15         return x;
16     }
17     void insert(int c,int loc){
18         int p=get_fail(last,loc);
19         if(!a[p][c]){
20             int now=++cnt,k=get_fail(f[p],loc);
21             l[now]=l[p]+2;
22             f[now]=a[k][c];a[p][c]=now;
23         }
24         last=a[p][c];
25     }
26 }P;
27 char fuck[N];
28 int main(){
29     scanf("%s",P.s);
30     int n=strlen(P.s);
31     for(int i=0;i<n;++i){
32         int ls=P.cnt;
33         P.insert(P.s[i]-a,i);
34         fuck[i]=(P.cnt-ls?1:0)+0;
35     }
36     puts(fuck);
37     return 0;
38 }

 

Ural 2040 Palindromes and Super Abilities 2