QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275532 | #7876. Cyclic Substrings | pengpeng_fudan# | AC ✓ | 97ms | 337504kb | C++17 | 1.5kb | 2023-12-04 20:10:06 | 2023-12-04 20:10:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n;
char s[6000010];
const int N=6000010;
int ch[N][10];
int fail[N],nm[N],len[N];
const int mod=998244353;
int cnt,tot;
int get_pre(char s[],int ct,int wei){
while(wei-len[ct]-1<=0||s[wei-len[ct]-1]!=s[wei]) ct=fail[ct];
return ct;
}
void palid_tr(char s[]){
cnt=tot=1;
fail[0]=1;fail[1]=0;len[0]=0;len[1]=-1;
fill(ch[0],ch[0]+10,0);fill(ch[1],ch[1]+10,0);
int sz=2*n;
for(int i=1;i<=sz;i++){
int ct=get_pre(s,tot,i);
if(!ch[ct][s[i]-'0']){
cnt++;
fill(ch[cnt],ch[cnt]+10,0);
nm[cnt]=0;
len[cnt]=len[ct]+2;
fail[cnt]=ch[get_pre(s,fail[ct],i)][s[i]-'0'];
ch[ct][s[i]-'0']=cnt;
}
tot=ch[ct][s[i]-'0'];
if(i>n) nm[tot]++;
}
}
int du[N];
void solve(){
cin>>n;
cin>>s+1;
for(int i=1;i<=n;i++) s[n+i]=s[i];
s[2*n+1]='\0';
palid_tr(s);
for(int i=2;i<=cnt;i++){
if(fail[i]>1) du[fail[i]]++;
}
queue<int> qe;
ll ans=0;
for(int i=0;i<=cnt;i++){
if(!du[i]) qe.push(i);
}
while(!qe.empty()){
int t=qe.front();qe.pop();
if(len[t]<=n)ans=(ans+1ll*nm[t]*nm[t]%mod*len[t]%mod)%mod;
du[fail[t]]--;
nm[fail[t]]+=nm[t];
if(fail[t]>=2&&!du[fail[t]]) qe.push(fail[t]);
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int _=1;
// cin>>_;
while(_--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 13800kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 2ms
memory: 13740kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13736kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 13676kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 0ms
memory: 13684kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 13720kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 2ms
memory: 13800kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: 0
Accepted
time: 27ms
memory: 121088kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
496166704
result:
ok 1 number(s): "496166704"
Test #9:
score: 0
Accepted
time: 94ms
memory: 337504kb
input:
3000000 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
890701718
result:
ok 1 number(s): "890701718"
Test #10:
score: 0
Accepted
time: 67ms
memory: 163508kb
input:
3000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
224009870
result:
ok 1 number(s): "224009870"
Test #11:
score: 0
Accepted
time: 68ms
memory: 337424kb
input:
3000000 8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...
output:
51985943
result:
ok 1 number(s): "51985943"
Test #12:
score: 0
Accepted
time: 76ms
memory: 337436kb
input:
3000000 1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...
output:
355676465
result:
ok 1 number(s): "355676465"
Test #13:
score: 0
Accepted
time: 74ms
memory: 301928kb
input:
3000000 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
output:
788510374
result:
ok 1 number(s): "788510374"
Test #14:
score: 0
Accepted
time: 91ms
memory: 314416kb
input:
3000000 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
691884476
result:
ok 1 number(s): "691884476"
Test #15:
score: 0
Accepted
time: 97ms
memory: 178004kb
input:
3000000 0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...
output:
701050848
result:
ok 1 number(s): "701050848"
Test #16:
score: 0
Accepted
time: 45ms
memory: 64084kb
input:
3000000 2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...
output:
486861605
result:
ok 1 number(s): "486861605"
Test #17:
score: 0
Accepted
time: 77ms
memory: 290556kb
input:
3000000 4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...
output:
450625621
result:
ok 1 number(s): "450625621"
Test #18:
score: 0
Accepted
time: 67ms
memory: 285228kb
input:
3000000 1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...
output:
649551870
result:
ok 1 number(s): "649551870"
Extra Test:
score: 0
Extra Test Passed