QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#730256 | #6234. 动物园 | qwertim | 100 ✓ | 97ms | 14352kb | C++20 | 830b | 2024-11-09 19:26:46 | 2024-11-09 19:26:47 |
Judging History
answer
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
void kmp(string str,int*pre,int*num){
int len=0;
num[1]=1;
fo(i,2,str.size()-1){
while(len&&str[i]!=str[len+1])len=pre[len];
pre[i]=(len+=(str[i]==str[len+1])),num[i]=num[len]+1;
}
}
string s;
int nxt[1000005],num[1000005];
long long ans;
void solve(){
cin>>s,s=' '+s,kmp(s,nxt,num),ans=1;
int tmp=0;
fo(i,2,s.size()-1){
// int len=pre[i-1];
while(tmp&&s[i]!=s[tmp+1])tmp=nxt[tmp];
if(s[i]==s[tmp+1])tmp++;
// cout<<i<<' '<<nxt[i]<<' '<<num[i]<<' ';
// int tmp=nxt[i]-1;
while(tmp>i/2)tmp=nxt[tmp];//cout<<'\n'<<tmp;
ans=ans*(num[tmp]+1)%1000000007;
// cout<<tmp<<' '<<num[tmp]+1<<'\n';
}
cout<<ans<<'\n';
}
signed main(){/*ios::sync_with_stdio(0);*/int t;cin>>t;while(t--)solve();return 0;}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 5628kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxpuvf abababababababababababababababababababababababdgcd abcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbafmlqh abacababacababacababacababacababacababacababadjyxq aabaacaabaacaabaacaabaacaabaacaabaacaabaacaabjtaxw
output:
592345761 371390093 121623872 675691877 481106999
result:
ok 5 number(s): "592345761 371390093 121623872 675691877 481106999"
Test #2:
score: 10
Accepted
time: 0ms
memory: 5848kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavtgynkaevpdhsdwswilx ababababababababababababababababababababababababababababababababababababababababababababababababa...
output:
469770619 76547694 933305750 902388437 803348921
result:
ok 5 number(s): "469770619 76547694 933305750 902388437 803348921"
Test #3:
score: 10
Accepted
time: 0ms
memory: 5536kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafcbwqryehhjfnlhglcnn ababababababababababababababababababababababababababababababababababababababababababababababababa...
output:
734885313 42387799 866611493 737798559 606697835
result:
ok 5 number(s): "734885313 42387799 866611493 737798559 606697835"
Test #4:
score: 10
Accepted
time: 0ms
memory: 5664kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
256900524 822524261 413461597 106784584 900200874
result:
ok 5 number(s): "256900524 822524261 413461597 106784584 900200874"
Test #5:
score: 10
Accepted
time: 2ms
memory: 5952kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
338653171 215976943 353365401 126668510 374446639
result:
ok 5 number(s): "338653171 215976943 353365401 126668510 374446639"
Test #6:
score: 10
Accepted
time: 7ms
memory: 6272kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
121054060 135829705 586084763 774583391 672914918
result:
ok 5 number(s): "121054060 135829705 586084763 774583391 672914918"
Test #7:
score: 10
Accepted
time: 16ms
memory: 6752kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
608896507 705745581 866882032 907283717 280168955
result:
ok 5 number(s): "608896507 705745581 866882032 907283717 280168955"
Test #8:
score: 10
Accepted
time: 50ms
memory: 11668kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
757739184 436599146 408735068 62286478 824797798
result:
ok 5 number(s): "757739184 436599146 408735068 62286478 824797798"
Test #9:
score: 10
Accepted
time: 90ms
memory: 14288kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
359993524 770772317 946742907 673664964 798002419
result:
ok 5 number(s): "359993524 770772317 946742907 673664964 798002419"
Test #10:
score: 10
Accepted
time: 97ms
memory: 14352kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
237665674 899763767 416501680 103496894 979807695
result:
ok 5 number(s): "237665674 899763767 416501680 103496894 979807695"
Extra Test:
score: 0
Extra Test Passed