QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#274618#7876. Cyclic SubstringsWilliamHuAC ✓276ms407844kbC++201.4kb2023-12-03 18:36:312023-12-03 18:36:32

Judging History

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

  • [2023-12-03 18:36:32]
  • 评测
  • 测评结果:AC
  • 用时:276ms
  • 内存:407844kb
  • [2023-12-03 18:36:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n, ch[6000010][11], fail[6000010], len[6000010], pos = 0, las;
char s[6000010];
long long mod = 998244353;
long long cnt[6000010], tmp[6000010];
void init()
{
	pos = 1;
	len[0] = 0;
	fail[0] = 1;
	len[1] = -1;
	fail[1] = 1;
	las = 0;
}
int find(int x, int now)
{
	while(s[now - len[x] - 1] != s[now])x = fail[x];
	return x;
}
void insert(int x)
{
	int p = find(las, x);
	if(! ch[p][s[x] - '0'])
	{
		len[++ pos] = len[p] + 2;
		fail[pos] = ch[find(fail[p], x)][s[x] - '0'];
		ch[p][s[x] - '0'] = pos;
	}
	++ cnt[las = ch[p][s[x] - '0']];
}
signed main() {
	cin>>n;
	s[0] = '*';
	for(int i = 1;i <= n;i ++)
	{
		cin>>s[i];
		s[n + i] = s[i];
	}
	init();
	for(int i = 1;i <= n;i ++)
	{
		insert(i);
		//cout<<i<<endl;
	}
	for(int i = 1;i <= pos;i ++)tmp[i] = cnt[i];
//	for(int i = 1;i <= n;i ++)
//	{
//		
//	}
	memset(ch, 0, sizeof(ch));
	memset(fail, 0, sizeof(fail));
	memset(cnt, 0, sizeof(cnt));
	memset(len, 0, sizeof(len));
	pos = 0;
	long long ans = 0;
	init();
	for(int i = 1;i <= 2 * n;i ++)
	{
		insert(i);
		//cout<<i<<endl;
	}
	for(int i = pos;i > 0;i --)
	{
		cnt[fail[i]] = (cnt[fail[i]]+ cnt[i]) % mod;
		tmp[fail[i]] = (tmp[fail[i]] + tmp[i]) % mod;
		if(len[i] <= n)ans = (ans + (cnt[i] - tmp[i] + mod) % mod * (cnt[i] - tmp[i] + mod) % mod * len[i] % mod) % mod;
	}
	cout<<ans;
	return 0;
} 


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 358344kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 8ms
memory: 358296kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 8ms
memory: 358392kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 15ms
memory: 358704kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 15ms
memory: 359148kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 11ms
memory: 356912kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 11ms
memory: 357720kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 91ms
memory: 375976kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

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

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 226ms
memory: 381516kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 236ms
memory: 407772kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 240ms
memory: 407724kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 236ms
memory: 384816kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 276ms
memory: 383032kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 228ms
memory: 385192kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 185ms
memory: 370980kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 240ms
memory: 379224kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 240ms
memory: 379100kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed