QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269615 | #7345. Circular Shift | BoulevardDust | WA | 4ms | 22276kb | C++20 | 1.4kb | 2023-11-29 20:15:38 | 2023-11-29 20:15:38 |
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];
int sum[26][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!=-1&&!trans[u][c])trans[u][c]=z,u=slink[u];
if(u==-1){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!=-1&&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=0;j<26;j++)
if(trans[i][j])ans+=sum[j][pos[i]-(maxlen[slink[i]]+2)+1]-sum[j][pos[i]-maxlen[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);
for(re int i=1;i<=n;i++){
memcpy(sum[i],sum[i-1],sizeof(sum[i]));
sum[i][s[i]-'a']++;
}
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 22276kb
input:
abaac
output:
4
result:
wrong answer 1st numbers differ - expected: '7', found: '4'