QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#274204#7876. Cyclic SubstringszhouhuanyiAC ✓647ms1029248kbC++141.5kb2023-12-03 12:52:082023-12-03 12:52:08

Judging History

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

  • [2023-12-03 12:52:08]
  • 评测
  • 测评结果:AC
  • 用时:647ms
  • 内存:1029248kb
  • [2023-12-03 12:52:08]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector> 
#define N 6000001
#define mod 998244353
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
string s;
int n,ans;
char c[N+1];
vector<int>E[N+1];
struct PAM
{
    int length,lst,leng[N+1],sn[N+1][10],fail[N+1],depth[N+1],sz[N+1];
    char st[N+1];
    vector<int>E[N+1];
    void init()
    {
		fail[0]=1,leng[1]=-1,length=1;
		return;
    }
    int get_fail(int p,int x)
    {
		while (st[x-leng[p]-1]!=st[x]) p=fail[p];
		return p;
    }
    void append(int x,char c)
    {
		st[x]=c;
		int p=get_fail(lst,x),q;
		if (!sn[p][c-'0']) q=++length,fail[q]=sn[get_fail(fail[p],x)][c-'0'],sn[p][c-'0']=q,leng[q]=leng[p]+2,depth[q]=depth[fail[q]]+1;
		lst=sn[p][c-'0'];
		if (x>n) sz[lst]++;
		return;
    }
    void append_fail()
    {
    	for (int i=2;i<=length;++i) E[fail[i]].push_back(i);
    	return;
	}
    void dfs(int x)
    {
    	for (int i=0;i<E[x].size();++i) dfs(E[x][i]),sz[x]+=sz[E[x][i]];
    	if (leng[x]<=n) Adder(ans,1ll*leng[x]*sz[x]%mod*sz[x]%mod);
    	return;
	}
};
PAM P;
int main()
{
    n=read(),P.init();
    for (int i=1;i<=n;++i) cin>>c[i]; 
    for (int i=1;i<=n;++i) P.append(i,c[i]);
    for (int i=1;i<=n;++i) P.append(i+n,c[i]);
    P.append_fail(),P.dfs(0),P.dfs(1),printf("%d\n",ans);
    return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 20ms
memory: 292408kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 43ms
memory: 294456kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 39ms
memory: 294580kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 41ms
memory: 294400kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 38ms
memory: 292572kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 27ms
memory: 294460kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 40ms
memory: 292540kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 132ms
memory: 543372kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 344ms
memory: 1029248kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 242ms
memory: 514160kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 419ms
memory: 919172kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 435ms
memory: 882848kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 314ms
memory: 722644kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 321ms
memory: 708608kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 574ms
memory: 518088kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 232ms
memory: 366004kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 647ms
memory: 650504kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 586ms
memory: 641756kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed