QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#272860#7876. Cyclic Substringsucup-team266#AC ✓625ms902988kbC++202.7kb2023-12-02 19:41:482023-12-02 19:41:48

Judging History

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

  • [2023-12-02 19:41:48]
  • 评测
  • 测评结果:AC
  • 用时:625ms
  • 内存:902988kb
  • [2023-12-02 19:41:48]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
class PalindromeAutomaton
{
	public:
		struct node
		{
			int len,fail;
			int cnt;
			int trans[12];
			int num;
			node(int _len=-1,int _fail=0,int _num=0)
			{
				num=_num;
				len=_len;
				fail=_fail;
				cnt=0;
				memset(trans,0,sizeof(trans));
			}
		}Node[6001000];
		vector<int> G[6001000];
		int tot,last;
		void clear()
		{
			Node[0]=node(0,1,0);
			Node[1]=node(-1,0,0);
			tot=2;
			last=0;
		}
		PalindromeAutomaton()
		{
			clear();
		}
		ll ans;
		void dfs(int x,int lim)
		{
			for(auto y:G[x])
			{
//				cerr<<x<<" -> "<<y<<endl;
				dfs(y,lim);
				Node[x].cnt+=Node[y].cnt;
			}
			if(Node[x].len<=lim&&Node[x].len>0)
			{
				ans=(ans+1ll*Node[x].cnt*Node[x].cnt%998244353*Node[x].len)%998244353;
//				cerr<<x<<" "<<Node[x].cnt<<" "<<Node[x].len<<endl;
			}
//			else
//				cerr<<". "<<x<<" "<<Node[x].cnt<<" "<<Node[x].len<<endl;
		}
		void solve(int lim)
		{
			for(int i=0;i<=tot;i++) if(i!=1)
				if(Node[i].fail>=0)
					G[Node[i].fail].pb(i);
			ans=0;
			dfs(1,lim);
			cout<<ans<<endl;
		}
		void extend(string s)
		{
			clear();
			int n=sz(s);
			s='!'+s;
			for(int i=1;i<=n;i++)
			{
				int x=s[i]-'0';
//				cout<<"# "<<x<<" ";
				while(s[i-Node[last].len-1]!=s[i]) last=Node[last].fail;
//				cout<<"$ "<<last<<endl;
				if(Node[last].trans[x])
				{
					if(i>(n/2))
						Node[Node[last].trans[x]].cnt++;
					last=Node[last].trans[x];
				}
				else
				{
					tot++;
					int v=Node[last].fail;
//					cout<<v<<endl;
					while(s[i-Node[v].len-1]!=s[i]) v=Node[v].fail;
					Node[tot]=node(Node[last].len+2,Node[v].trans[x],Node[Node[v].trans[x]].num+1);
					if(i>(n/2))
						Node[tot].cnt++;
					Node[last].trans[x]=tot;
					last=Node[last].trans[x];
				}
//				cout<<"! "<<last<<endl;
//				cout<<"& "<<Node[last].len<<endl;
//				cerr<<Node[last].cnt<<" "<<Node[last].fail<<endl;
			}
			solve(n/2);
		}
}pam;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	pam.extend(s+s);
	return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 519544kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 31ms
memory: 519472kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 28ms
memory: 519296kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 28ms
memory: 519316kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 32ms
memory: 519356kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 31ms
memory: 519260kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 28ms
memory: 519320kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 169ms
memory: 646984kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 464ms
memory: 902988kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 261ms
memory: 588260kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 499ms
memory: 809020kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 493ms
memory: 777648kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 370ms
memory: 654880kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 377ms
memory: 630384kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 571ms
memory: 579408kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

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

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 625ms
memory: 602460kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 593ms
memory: 598832kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed