UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213850#2411. 三元组xuewentao07ms1264kbC++111.1kb2024-11-13 21:57:062024-11-13 23:09:44

answer

#include<bits/stdc++.h>
#define LL long long

using namespace std;

const int mod = 998244353;
const int maxn = 1010;

const int B = 28;

int h[maxn];
int hr[maxn];

int p[maxn];

int n;

int calh(int l, int r) {
	return (h[r] - (h[l-1] * p[r - l + 1] % mod) + mod ) % mod;
}

int calhr(int l, int r) {
	return (hr[l] - (hr[r+1] * p[r - l + 1] % mod) + mod ) % mod;
}

bool check(int l, int r) {
	return calh(l, r) == calhr(l, r);
}

void init() {
	p[0] = 1;
	for (int i = 1; i < maxn; i++) p[i] = (LL)p[i-1] * B % mod;
}

void cal(string s) {
	n = s.size();
	s = ' ' + s;
	for (int i = 1; i <= n; i++) {
		h[i] = ((LL)h[i-1] * B + s[i] - 'a' + 1) % mod;
	}
	
	for (int i = n; i >= 1; i--) {
		hr[i] = ((LL)hr[i+1] * B + s[i] - 'a' + 1) % mod;
	}
	LL res = 0;
	for (int l = 1; l <= n; l++) {
		for (int m = l; m <= n; m++) {
			for (int r = m+1; r <= n; r++) {
				if (check(l, m) && check(m+1, r)) {
					res = (res + (LL)l * r % mod) % mod;
				}
			}
		}
	}
	cout << res << endl;
}

int main() {
	init();
	int T;
	cin >> T;
	while (T--) {
		string s;
		cin >> s;
		cal(s);
	}
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1260kb

input:

10
kyynjrttqngurtcvcjnnuqmstrntnpghrqqqp
lqfnqzykyzzynqnqyywzzwwfnyzlwykznyfhyknfnk
fuhjuhhuhuqjuuqu...

output:

0
0
0
6
0
0
0
0
0
12

result:

wrong answer 1st lines differ - expected: '27169', found: '0'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1256kb

input:

10
eedleeeldeededlllleldleeeleleddleellele
kllrnnjqjniqqknjmlfcirjyrycfrkyqqjrky
uksfueafjuarusziepe...

output:

0
12
0
2174
0
0
212
506
0
0

result:

wrong answer 1st lines differ - expected: '66808', found: '0'

Test #3:

score: 0
Wrong Answer
time: 7ms
memory: 1264kb

input:

10
aaqzqvvvvzaqvazzvqqzqzavaaavvqaqqqvaqavvavvaavzvqzavaqvzvaazavqavazzvqvqazzvzvqqaqaaqqazqaqqzzzza...

output:

15138
39386
77120
5012
66114
46522
34410
79266
17822
72690

result:

wrong answer 1st lines differ - expected: '6230886', found: '15138'

Test #4:

score: 0
Time Limit Exceeded

input:

10
bsppzzcusncccbbpgguszngssnzncsnzpppbpuuczgcbucpupcubbzubsncncpbgbuzungnznsnpncpbugzcpguungzgcnbng...

output:

1266152
2043648
897004
1772013
2250530
3023416
2906458
5495131

result:


Test #5:

score: 0
Time Limit Exceeded

input:

10
pzrpbfgjbnqhbpzohubzunqjnujfbfgazjqeaqhjgppqnogagegebuebhbeoeboouoojhbhaahjooggrozeephgqfrzrfrpjz...

output:

2426518
3101742
2742266
4681096
1799416
3254514

result:


Test #6:

score: 0
Time Limit Exceeded

input:

100000
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

12670
0
1056
0
0
2
4160
210
5852
0
0
5700
14060
0
3802
0
6642
702
7250
0
13642
0
0
5066
12582
2294
1...

result:


Test #7:

score: 0
Time Limit Exceeded

input:

10000
iqtuiwnrdznudrwdznuwoyhzhhmiqytqhdqjuhihyuyrmwqurmdzdwiidomqrihqrjzyjwytjhznuwuhiojnhiduhytjir...

output:

2456902
6314262
3368562
5801456
3013956
4763344
2152954
659680

result:


Test #8:

score: 0
Runtime Error

input:

1000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:


result:


Test #9:

score: 0
Runtime Error

input:

100
yuuxiorshssxoiyxrsxyyyuxsuyuhsruhxisoyiuuixhrsxuxyyxxosihhyisxxohoyiiurxhixrruryiihxhsxhxuhoroou...

output:


result:


Test #10:

score: 0
Runtime Error

input:

10
qvvvvqqgqgvvvgqvgqvqqwqgwqvqggvgqqqgqvwwggwwqqqqqwvwqggqvgqqvvvvvwqvqvvgvvqgvwqggwqqvvwwvvgwwwgqg...

output:


result: