QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#274566#7876. Cyclic SubstringsMurphy_AC ✓247ms759456kbC++141.1kb2023-12-03 17:38:592023-12-03 17:39:00

Judging History

你现在查看的是最新测评结果

  • [2023-12-03 17:39:00]
  • 评测
  • 测评结果:AC
  • 用时:247ms
  • 内存:759456kb
  • [2023-12-03 17:38:59]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define re register
#define il inline
#define N 6000006
#define mod 998244353
using namespace std;
char s[N];
int las,ch[N][26],len[N],fail[N],ct,n;
ll cnt[N],tmp[N];
void init() {
	ct=1;las=0;
	s[0]='*';
	len[0]=0;fail[0]=1;
	len[1]=-1;fail[1]=1;
}

int getfail(int pos,int x) { while(s[pos-len[x]-1]!=s[pos]) x=fail[x];return x;}

void insert(int pos,char c) {
	int nw=getfail(pos,las);
	if(!ch[nw][c-'a']) {
		len[++ct]=len[nw]+2;
		fail[ct]=ch[getfail(pos,fail[nw])][c-'a'];
		ch[nw][c-'a']=ct;
	}
	++cnt[las=ch[nw][c-'a']];
}

ll solve() {
	ll ans=0;
	for(int i=ct;i>=0;--i) cnt[fail[i]]=(cnt[fail[i]]+cnt[i])%mod;
	for(int i=ct;i>=0;--i) tmp[fail[i]]=(tmp[fail[i]]+tmp[i])%mod;
	for(int i=2;i<=ct;++i) cnt[i]=(cnt[i]-tmp[i]+mod)%mod;
	for(int i=2;i<=ct;++i) if(len[i]<=n) ans=(ans+(cnt[i]*(cnt[i]*len[i]%mod)%mod)%mod)%mod;
	return ans;
}

int main()
{
	cin>>n>>(s+1);
	init();
	for(int i=1;i<=n;++i) s[n+i]=s[i]; 
	for(int i=1;i<=n;++i) insert(i,s[i]);
	for(int i=0;i<=ct;++i) tmp[i]=cnt[i];
	for(int i=n+1;i<=2*n;++i) insert(i,s[i]);
	cout<<solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11804kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 0ms
memory: 11756kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 2ms
memory: 11632kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 11628kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 2ms
memory: 11804kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 0ms
memory: 11636kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 2ms
memory: 11756kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 47ms
memory: 263316kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 223ms
memory: 759344kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 175ms
memory: 354840kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 154ms
memory: 759292kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 124ms
memory: 759456kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 180ms
memory: 656616kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 227ms
memory: 680140kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 193ms
memory: 390360kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 118ms
memory: 127392kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 247ms
memory: 628224kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 184ms
memory: 609128kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed