QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269611 | #7345. Circular Shift | BoulevardDust | TL | 15ms | 77112kb | C++20 | 1.1kb | 2023-11-29 20:11:58 | 2023-11-29 20:11:59 |
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!=-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=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: 100
Accepted
time: 1ms
memory: 5636kb
input:
abaac
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
aaa
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7856kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
z
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5560kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 1ms
memory: 7744kb
input:
az
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5564kb
input:
za
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 7664kb
input:
zz
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
abc
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 1ms
memory: 7716kb
input:
aab
output:
3
result:
ok 1 number(s): "3"
Test #11:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
baa
output:
3
result:
ok 1 number(s): "3"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
dbda
output:
5
result:
ok 1 number(s): "5"
Test #13:
score: 0
Accepted
time: 0ms
memory: 5864kb
input:
dacc
output:
4
result:
ok 1 number(s): "4"
Test #14:
score: 0
Accepted
time: 0ms
memory: 5660kb
input:
cdaca
output:
6
result:
ok 1 number(s): "6"
Test #15:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
cddcc
output:
8
result:
ok 1 number(s): "8"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5628kb
input:
adcbdb
output:
7
result:
ok 1 number(s): "7"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
cccccc
output:
6
result:
ok 1 number(s): "6"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
ccdcabb
output:
9
result:
ok 1 number(s): "9"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5560kb
input:
bcbddca
output:
8
result:
ok 1 number(s): "8"
Test #20:
score: 0
Accepted
time: 1ms
memory: 7676kb
input:
cadababb
output:
11
result:
ok 1 number(s): "11"
Test #21:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
bdddcbbc
output:
11
result:
ok 1 number(s): "11"
Test #22:
score: 0
Accepted
time: 0ms
memory: 5812kb
input:
acdaabcdb
output:
10
result:
ok 1 number(s): "10"
Test #23:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
abcabdcad
output:
11
result:
ok 1 number(s): "11"
Test #24:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
bccbccccda
output:
17
result:
ok 1 number(s): "17"
Test #25:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
bbdddadcab
output:
14
result:
ok 1 number(s): "14"
Test #26:
score: 0
Accepted
time: 3ms
memory: 40808kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
300000
result:
ok 1 number(s): "300000"
Test #27:
score: 0
Accepted
time: 14ms
memory: 43080kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
300000
result:
ok 1 number(s): "300000"
Test #28:
score: 0
Accepted
time: 15ms
memory: 77112kb
input:
yxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
300000
result:
ok 1 number(s): "300000"
Test #29:
score: 0
Accepted
time: 8ms
memory: 44032kb
input:
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn...
output:
299988
result:
ok 1 number(s): "299988"
Test #30:
score: -100
Time Limit Exceeded
input:
cacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacaca...