QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200255 | #7345. Circular Shift | whsyhyyh# | TL | 35ms | 120408kb | C++14 | 1.2kb | 2023-10-04 16:05:04 | 2023-10-04 16:05:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+9;
int n,f[N];
char s[N];
int las,cnt,head[N],tot;
struct SAM{
int ch[26],len,fa;
SAM(){memset(ch,0,sizeof(ch));len=fa=0;}
}t[N];
void ins(int c){
int p=las,np=las=++cnt;
t[np].len=t[p].len+1;
for(;p&&!t[p].ch[c];p=t[p].fa) t[p].ch[c]=np;
if(!p) t[np].fa=1;
else{
int q=t[p].ch[c];
if(t[q].len==t[p].len+1) t[np].fa=q;
else{
int nq=++cnt;t[nq]=t[q];
t[nq].len=t[p].len+1;
t[q].fa=t[np].fa=nq;
for(;p&&t[p].ch[c]==q;p=t[p].fa) t[p].ch[c]=nq;
}
}
}
int main(){
cnt=1,las=1;
scanf("%s",s);n=strlen(s);
for(int i=0;i<n;i++) ins(s[i]-'a');
int ans=0;
int u=1;f[1]=1;
for(int i=0;i<n;i++){
u=t[u].ch[s[i]-'a'];
int v=u;
while(!f[v]){
for(int j=i-t[v].len+1;j<i-t[t[v].fa].len;j++)
if(t[v].ch[s[j]-'a']){
ans++;
}
int j=i-t[t[v].fa].len;
ans+=(t[t[v].fa].ch[s[j]-'a']>0);
f[v]=1,v=t[v].fa;
}
}
printf("%d\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 16ms
memory: 119456kb
input:
abaac
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 12ms
memory: 117372kb
input:
aaa
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 11ms
memory: 117640kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 7ms
memory: 116784kb
input:
z
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 7ms
memory: 116216kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 15ms
memory: 117336kb
input:
az
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 4ms
memory: 116744kb
input:
za
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 12ms
memory: 119276kb
input:
zz
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 20ms
memory: 118088kb
input:
abc
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 8ms
memory: 116836kb
input:
aab
output:
3
result:
ok 1 number(s): "3"
Test #11:
score: 0
Accepted
time: 11ms
memory: 118028kb
input:
baa
output:
3
result:
ok 1 number(s): "3"
Test #12:
score: 0
Accepted
time: 20ms
memory: 117784kb
input:
dbda
output:
5
result:
ok 1 number(s): "5"
Test #13:
score: 0
Accepted
time: 15ms
memory: 116992kb
input:
dacc
output:
4
result:
ok 1 number(s): "4"
Test #14:
score: 0
Accepted
time: 18ms
memory: 118092kb
input:
cdaca
output:
6
result:
ok 1 number(s): "6"
Test #15:
score: 0
Accepted
time: 11ms
memory: 119380kb
input:
cddcc
output:
8
result:
ok 1 number(s): "8"
Test #16:
score: 0
Accepted
time: 11ms
memory: 116404kb
input:
adcbdb
output:
7
result:
ok 1 number(s): "7"
Test #17:
score: 0
Accepted
time: 7ms
memory: 117648kb
input:
cccccc
output:
6
result:
ok 1 number(s): "6"
Test #18:
score: 0
Accepted
time: 3ms
memory: 117040kb
input:
ccdcabb
output:
9
result:
ok 1 number(s): "9"
Test #19:
score: 0
Accepted
time: 4ms
memory: 118060kb
input:
bcbddca
output:
8
result:
ok 1 number(s): "8"
Test #20:
score: 0
Accepted
time: 3ms
memory: 116936kb
input:
cadababb
output:
11
result:
ok 1 number(s): "11"
Test #21:
score: 0
Accepted
time: 3ms
memory: 116652kb
input:
bdddcbbc
output:
11
result:
ok 1 number(s): "11"
Test #22:
score: 0
Accepted
time: 4ms
memory: 116044kb
input:
acdaabcdb
output:
10
result:
ok 1 number(s): "10"
Test #23:
score: 0
Accepted
time: 3ms
memory: 116564kb
input:
abcabdcad
output:
11
result:
ok 1 number(s): "11"
Test #24:
score: 0
Accepted
time: 0ms
memory: 117116kb
input:
bccbccccda
output:
17
result:
ok 1 number(s): "17"
Test #25:
score: 0
Accepted
time: 4ms
memory: 117716kb
input:
bbdddadcab
output:
14
result:
ok 1 number(s): "14"
Test #26:
score: 0
Accepted
time: 22ms
memory: 118004kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
300000
result:
ok 1 number(s): "300000"
Test #27:
score: 0
Accepted
time: 8ms
memory: 119236kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
300000
result:
ok 1 number(s): "300000"
Test #28:
score: 0
Accepted
time: 35ms
memory: 120408kb
input:
yxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
300000
result:
ok 1 number(s): "300000"
Test #29:
score: 0
Accepted
time: 20ms
memory: 117252kb
input:
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn...
output:
299988
result:
ok 1 number(s): "299988"
Test #30:
score: -100
Time Limit Exceeded
input:
cacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacaca...