QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276009#7876. Cyclic SubstringszkzqwqAC ✓82ms357792kbC++172.1kb2023-12-05 14:21:432023-12-05 14:21:44

Judging History

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

  • [2023-12-05 14:21:44]
  • 评测
  • 测评结果:AC
  • 用时:82ms
  • 内存:357792kb
  • [2023-12-05 14:21:43]
  • 提交

answer

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)	x.begin(),x.end()
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int mod = 998244353;
const int N = 1e5 + 5;

struct PAM {
	static const int maxn = 6e6 + 5;;
	int S[maxn];
	int nxt[maxn][10];
	int fail[maxn], cnt[maxn], num[maxn], len[maxn];
	int last, n, p;
	int newnode(int l) {
		for (int i = 0; i < 10; ++i) nxt[p][i] = 0;
		cnt[p] = 0;	num[p] = 0;	len[p] = l;
		return p++;
	}
	PAM() { clear(); }
	void clear() {
		p = 0;	newnode(0);	newnode(-1);
		last = 0;	n = 0;
		S[n] = -1;	fail[0] = 1;
	}
	int get_fail(int x) {
		while (S[n - len[x] - 1] != S[n]) x = fail[x];
		return x;
	}
	void insert(int c) {
		c -= '0';	S[++n] = c;
		int cur = get_fail(last);
		if (!nxt[cur][c]) {
			int now = newnode(len[cur] + 2);
			fail[now] = nxt[get_fail(fail[cur])][c];
			nxt[cur][c] = now;
			num[now] = num[fail[now]] + 1;
		}
		last = nxt[cur][c];
		//cnt[last]++;
	}
	void count() {
		for (int i = p - 1; i >= 0; --i) {
			if (fail[i] >= 2)	cnt[fail[i]] += cnt[i];
		}
	}
	//ll solve() {//P3649
	//	count();
	//	ll res = 0;
	//	for (int i = 2; i <= p - 1; ++i)	res = max(res, 1ll * cnt[i] * len[i]);
	//	return res;
	//}x
	ll solve() {
		count();
		ll res = 0;
		for (int i = 2; i <= p - 1; ++i) {
			if (len[i] <= n / 2) {
				//cout << "-->" << cnt[i] << ' ' << len[i] << endl;
				(res += 1ll * cnt[i] * cnt[i] % mod * len[i] % mod) %= mod;
			}
		}
		return res;
	}
};
PAM pam;
//n<=3e6, ∑={0-9}
//对所有不同的回文子串求 ∑cnt^2*len
//回文子串:s[i-j] 或 s[i-n] + s[1,j]
void AC() {
	int n;	cin >> n;
	string s;	cin >> s;
	s = ' ' + s;
	for (int i = 1; i <= 2 * n; ++i) {
		if (i <= n)	pam.insert(s[i]);
		else {
			pam.insert(s[i - n]);
			++pam.cnt[pam.last];
		}
	}
	cout << pam.solve() << endl;
}
signed main() {
	ios;
	int o_o = 1;
	//cin >> o_o;
	while (o_o--)  AC();
	return 0;
}
/*
01010
*/

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

详细

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

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

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

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

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 71ms
memory: 187168kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 57ms
memory: 357792kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 58ms
memory: 357728kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 82ms
memory: 321024kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 74ms
memory: 331408kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

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

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 35ms
memory: 88296kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 48ms
memory: 311484kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 55ms
memory: 302636kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed