UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213851#2411. 三元组nodgd40945ms1236kbC++111.3kb2024-11-13 21:57:132024-11-13 23:09:53

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000000 + 5;
const int B = 31, P = 998244353;

int T, N;
char s[MAX_N];
int h1[MAX_N], h2[MAX_N], pw[MAX_N];
int sl[MAX_N], sr[MAX_N];


int main() {
    scanf("%d", &T);
    for (int tid = 1; tid <= T; tid ++) {
        scanf("%s", s + 1);
        N = strlen(s + 1);
        h1[0] = h2[N + 1] = 0, pw[0] = -1;
        for (int i = 1; i <= N; i ++) {
            pw[i] = pw[i - 1] * B;
            sl[i] = sr[i] = 0;
        }
        for (int i = 1; i <= N; i ++) {
            h1[i] = h1[i - 1] * B + (s[i] - 'a' + 1);
        }
        for (int i = N; i >= 1; i --) {
            h2[i] = h2[i + 1] * B + (s[i] - 'a' + 1);
        }
        for (int i = 1; i <= N; i ++) {
            for (int j = i; j <= N; j ++) {
                int t1 = h1[j] + h1[i - 1] * pw[j - i + 1];
                int t2 = h2[i] + h2[j + 1] * pw[j - i + 1];
                if (t1 == t2) {
                    sr[i] += j;
                    sr[i] -= sr[i] >= P ? P : 0;
                    sl[j] += i;
                    sl[j] -= sl[j] >= P ? P : 0;
                }
            }
        }
        int ans = 0;
        for (int i = 1; i < N; i ++) {
            ans = (ans + 1ll * sl[i] * sr[i + 1]) % P;
        }
        printf("%d\n", ans);
    }
    return 0;
}

详细

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

10
kyynjrttqngurtcvcjnnuqmstrntnpghrqqqp
lqfnqzykyzzynqnqyywzzwwfnyzlwykznyfhyknfnk
fuhjuhhuhuqjuuqu...

output:

27169
35530
31188
37732
65217
28457
133147
22985
43141
10759

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

10
eedleeeldeededlllleldleeeleleddleellele
kllrnnjqjniqqknjmlfcirjyrycfrkyqqjrky
uksfueafjuarusziepe...

output:

66808
20895
14900
37820
39914
38054
29364
37426
38775
29747

result:

ok 10 lines

Test #3:

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

input:

10
aaqzqvvvvzaqvazzvqqzqzavaaavvqaqqqvaqavvavvaavzvqzavaqvzvaazavqavazzvqvqazzvzvqqaqaaqqazqaqqzzzza...

output:

6230886
3556080
11802598
3833447
8206626
3621091
5300328
6484259
3025216
18509610

result:

wrong answer 3rd lines differ - expected: '11774834', found: '11802598'

Test #4:

score: 10
Accepted
time: 3ms
memory: 1236kb

input:

10
bsppzzcusncccbbpgguszngssnzncsnzpppbpuuczgcbucpupcubbzubsncncpbgbuzungnznsnpncpbugzcpguungzgcnbng...

output:

559443824
305794405
414279981
912202469
497470943
263140764
422669314
204178180
579056344
460822521

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 5ms
memory: 1232kb

input:

10
pzrpbfgjbnqhbpzohubzunqjnujfbfgazjqeaqhjgppqnogagegebuebhbeoeboouoojhbhaahjooggrozeephgqfrzrfrpjz...

output:

442803205
483459867
245377898
502317569
156660068
301473465
396310915
489306288
862513697
753896393

result:

ok 10 lines

Test #6:

score: 0
Wrong Answer
time: 937ms
memory: 1212kb

input:

100000
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

341665830
471661
1999742
543480
459540
202296822
191363172
1241848
713235
369157
575809
170913820
68...

result:

wrong answer 2019th lines differ - expected: '1809581', found: '1912690'

Test #7:

score: 0
Time Limit Exceeded

input:

10000
iqtuiwnrdznudrwdznuwoyhzhhmiqytqhdqjuhihyuyrmwqurmdzdwiidomqrihqrjzyjwytjhznuwuhiojnhiduhytjir...

output:

452745570
395658802
415729637
581286624
608938037
896800719
445556994
913683462
444333468
228535301
...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

1000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

100
yuuxiorshssxoiyxrsxyyyuxsuyuhsruhxisoyiuuixhrsxuxyyxxosihhyisxxohoyiiurxhixrruryiihxhsxhxuhoroou...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

10
qvvvvqqgqgvvvgqvgqvqqwqgwqvqggvgqqqgqvwwggwwqqqqqwvwqggqvgqqvvvvvwqvqvvgvvqgvwqggwqqvvwwvvgwwwgqg...

output:


result: