QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269609 | #7345. Circular Shift | BoulevardDust | WA | 1ms | 5640kb | C++20 | 1.1kb | 2023-11-29 20:11:22 | 2023-11-29 20:11:23 |
Judging History
answer
#include<bits/stdc++.h>
#define N 600005
#define re
#define ll long long
using namespace std;
int n,m,k,q,T;
char s[N];
ll ans;
struct SAM{
int n,maxlen[N<<1],trans[N<<1][26],slink[N<<1],u,pos[N<<1];
void clear(){memset(trans[0],0,sizeof(trans[0]));slink[0]=-1;n=0;u=0;}
void add(char ch,int pos0){
int z=++n,c=ch-'a';maxlen[z]=maxlen[u]+1;
pos[z]=pos0;
while((~u)&&!trans[u][c])trans[u][c]=z,u=slink[u];
if(~u){slink[z]=0,u=z;return;}
int x=trans[u][c];
if(maxlen[u]+1==maxlen[x]){slink[z]=x;u=z;return;}
int y=++n;maxlen[y]=maxlen[u]+1,slink[y]=slink[x];pos[y]=pos[x];
memcpy(trans[y],trans[x],sizeof(trans[y]));
slink[x]=y;slink[z]=y;
while((~u)&&trans[u][c]==x)trans[u][c]=y,u=slink[u];
u=z;
}
void Solve(){
for(re int i=n;i>=1;i--){
for(re int j=maxlen[slink[i]]+2;j<=maxlen[i];j++)
ans+=!!trans[i][s[pos[i]-j+1]-'a'];
ans+=!!trans[slink[i]][ s[pos[i]-maxlen[slink[i]] ]-'a' ];
}
}
}S;
int main(){
scanf("%s",s+1);
n=strlen(s+1);
S.slink[0]=-1;
for(re int i=1;i<=n;i++)S.add(s[i],i);
S.Solve();
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5640kb
input:
abaac
output:
3
result:
wrong answer 1st numbers differ - expected: '7', found: '3'