QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563066#7876. Cyclic SubstringsArvinAC ✓130ms478532kbC++201.7kb2024-09-14 01:44:292024-09-14 01:44:29

Judging History

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

  • [2024-09-14 01:44:29]
  • 评测
  • 测评结果:AC
  • 用时:130ms
  • 内存:478532kb
  • [2024-09-14 01:44:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ld long double
#define lll  __int128
#define dhm std::fixed<<std::setprecision
#define prq priority_queue
using ll = long long;
using ull = unsigned long long;
int T;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
const int cd = 6e6+10;
struct pam {
	int len[cd];
	int trie[cd][10];
	int fail[cd];
	int pos;
	int tot = 1;
	int num[cd];
	int cur;
	int lst = 0;
	pam() {
		len[1] = -1;
		fail[0] = 1;
	}
	void init(string s) {
		for(int i = 0 ; i < s.size(); i ++) {
			auto getfail = [&](int x,int i)->int {
				while(i-len[x]-1<0||s[i]!=s[i-len[x]-1])x = fail[x];
				return x;
			};
			pos = getfail(cur,i);
			if(!trie[pos][s[i]-'0']) {
				fail[++tot] = trie[getfail(fail[pos],i)][s[i]-'0'];
				trie[pos][s[i]-'0'] = tot;
				len[tot] = len[pos] + 2;
			}
			cur = trie[pos][s[i]-'0'];
			num[cur]++;
		}
	}
}PAM,dbPAM;
const int mod = 998244353;
void solve() {
	int n;
	std::cin>>n;
	string s;
	std::cin>>s;
	PAM.init(s);
	s+=s;
	dbPAM.init(s);
	for(int i = PAM.tot; i >= 2; i --) {
		PAM.num[PAM.fail[i]] += PAM.num[i];
		//std::cout<<PAM.num[i]<<" "<<PAM.len[i]<<endl;
	}
	ll ans = 0;
	for(int i = dbPAM.tot; i >= 2; i --) {
		dbPAM.num[dbPAM.fail[i]] += dbPAM.num[i];
		dbPAM.num[i] -= PAM.num[i];
		if(dbPAM.len[i]<=n)
			ans = (ans + 1ll*dbPAM.len[i]*dbPAM.num[i]%mod*dbPAM.num[i]%mod)%mod;
	}
	std::cout<<ans<<endl;
}
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	T = 1;
	//std::cin>>T;
	while(T --)
		solve();
	return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 14060kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

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

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 130ms
memory: 473876kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 105ms
memory: 282068kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

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

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 95ms
memory: 478532kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

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

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 95ms
memory: 434316kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 80ms
memory: 332704kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 44ms
memory: 115368kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 100ms
memory: 388556kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 88ms
memory: 372524kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed