We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<algorithm>#include<cstdio>usingnamespacestd;typedeflonglongll;#define FOR(i, a, b) for (int i = (a); i < (b); i++)#define ROF(i, a, b) for (int i = (b); --i >= (a); )intri(){intx;scanf("%d",&x);returnx;}constintN=100000;chara[N+1];structNode{intsuff,l,c[26],cnt;}b[N+2];intgetSuff(inti,intx){while(i-1-b[x].l<0||a[i-1-b[x].l]!=a[i])x=b[x].suff;returnx;}intmain(){b[0].suff=1;b[0].l=0;b[1].suff=1;b[1].l=-1;scanf("%s",a);intx=1,y=2;for(inti=0;a[i];i++){x=getSuff(i,x);if(!b[x].c[a[i]-'a']){b[y].l=b[x].l+2;b[y].suff=b[getSuff(i,b[x].suff)].c[a[i]-'a'];b[y].cnt=0;b[x].c[a[i]-'a']=y++;}x=b[x].c[a[i]-'a'];b[x].cnt++;}ROF(i,0,y)b[b[i].suff].cnt+=b[i].cnt;llans=0;FOR(i,2,y){intc=b[i].cnt;ans+=ll(c-1)*c/2;}printf("%lld\n",ans%1000000007);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Palindromic Border
You are viewing a single comment's thread. Return to all comments →