QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#837136 | #4475. 重复 | hhoppitree | 100 ✓ | 79ms | 19620kb | C++17 | 1.3kb | 2024-12-29 16:40:10 | 2024-12-29 16:40:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2005, P = 998244353;
int nxt[N], ch[N][26], mx[N], f[N][N];
signed main() {
int m; scanf("%d", &m);
string S; cin >> S;
int n = S.size(); S = ' ' + S;
for (int i = 2, j = 0; i <= n; ++i) {
while (j && S[i] != S[j + 1]) j = nxt[j];
if (S[i] == S[j + 1]) ++j;
nxt[i] = j;
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < 26; ++j) {
if (i != n && S[i + 1] - 'a' == j) ch[i][j] = i + 1;
else ch[i][j] = ch[nxt[i]][j];
if (ch[i][j]) mx[i] = j;
}
}
f[0][0] = 1;
for (int i = 0; i <= m; ++i) {
for (int j = 0; j <= n; ++j) {
for (int k = mx[j]; k < 26; ++k) {
((f[i + 1][ch[j][k]] += f[i][j]) >= P) && (f[i + 1][ch[j][k]] -= P);
}
}
}
int res = 0;
for (int i = 0; i <= n; ++i) {
int now = i;
for (int j = 1; j <= m; ++j) {
res = (res + 1ll * (25 - mx[now]) * f[m - j][i]) % P;
now = ch[now][mx[now]];
if (!now) break;
}
res += (i != 0 && now == i);
}
int mul = 1;
for (int i = 1; i <= m; ++i) mul = 26ll * mul % P;
printf("%d\n", (mul - res + P) % P);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 4124kb
input:
5 utxpwmyovh
output:
11873600
result:
ok 1 number(s): "11873600"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3956kb
input:
30 bhekhtazrdskusizkimkthaelctvab
output:
690391422
result:
ok 1 number(s): "690391422"
Test #3:
score: 10
Accepted
time: 1ms
memory: 4296kb
input:
50 flfsflfsflfsflfsflfs
output:
158554587
result:
ok 1 number(s): "158554587"
Test #4:
score: 10
Accepted
time: 1ms
memory: 4204kb
input:
85 ctiqhwibrrljvrsogddkjxtsoucmtqjducznwvslnjkpyjvamdnknyxslwowmewhcwkdqymljsshwljpandxjmswqukroyaydve
output:
767635094
result:
ok 1 number(s): "767635094"
Test #5:
score: 10
Accepted
time: 2ms
memory: 4768kb
input:
193 mtkbajqtvduekczyzxrbtkqikjzclxxmaqrntemikivczxlieyqpuwkkofoltttjtbmknbkxqhepnkvmgiwxwwravldcghnhrxlfbjgutuatjgkunafziudxvfzgarytoandeepptetgbfobufwdrfssqprtolqaubdagfgxkeqpcojrhthdgzswhidcnlnbf
output:
834222930
result:
ok 1 number(s): "834222930"
Test #6:
score: 10
Accepted
time: 0ms
memory: 5288kb
input:
300 gpqfkteejltpewqtpwxjdopigynimneadkrgdzbvdteebapyvwesbsqhgofqhlfxemrxykjzbiaqgcmuoopmrnbgcgzqjenpecjcainzisqdyqvqqulprhopucebwhlsilmnhzvjwxvjqsmgdmhwrefyugibvwxnixdmpfhwrtpnrltdcwctpcvccplfbtifipqnwnbf
output:
772953201
result:
ok 1 number(s): "772953201"
Test #7:
score: 10
Accepted
time: 16ms
memory: 6372kb
input:
300 oyczstbzwdszrmnxmledokfkvddpyfaodutuzogvlisopudyvohaxxonfcgcrhbsulufholejrspjxckplrqhrencahhiaqaounemkxvhzheangultnezzhtvaousltkauurapfgvvfhvradwkykqilhupxwtqutdqfsxmtfmzdddcxljxbmchsmrgpnysnuqparmrepgzuzpbiosfbabmawjpxpvzczlzfmntuvvcftgozdntwbdmrkvvxfvqkghvbdcguuoesvpxuyzapqbsdyhoddvfzvoptsjihq...
output:
251633039
result:
ok 1 number(s): "251633039"
Test #8:
score: 10
Accepted
time: 33ms
memory: 10492kb
input:
880 abelngddxylbyvkgrsbpdegqwohgshsrtxlxuwhgstkvzfeiqrjbopwwxiudovarjhxkdoewrbwcxfliemxsggkzvpfmlkeimsejvqhocmhpvimcpvwhtlqopvfngwnrmuwwjetcagedcgdwpjglpvyotlerqbaepbgbesbxqdnwckudhjfdhbqogohaireinbczffglyghnsvptzdurzwofybpjrzopkfxnlnmtaiqjnmbfuyjpcxtwicwxrovqixxqbsrzsqhzekzkyezwdsgxwdackzdrupfyyoct...
output:
893745577
result:
ok 1 number(s): "893745577"
Test #9:
score: 10
Accepted
time: 15ms
memory: 13388kb
input:
1998 bggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwt
output:
758188091
result:
ok 1 number(s): "758188091"
Test #10:
score: 10
Accepted
time: 79ms
memory: 19620kb
input:
2000 lvcmwzggyrdooanqnloalpaiuphxpfrozonodonneognbfgyzlumraoqbtstrpesciausnzqaiwxougtwohptrakhmujgdrahfewscrcdxycrtjenzvycwehnuovgbjdipjzaoiimehrpaxzhzqbnlbaigyzpwjppikbaqrcxwwvtyuuadmyadhmrdmaockaoocetpuavaveanykqfvsmixjwijumyjucltbzqfsefvrpjrnyotjhatirvgbeygxoiweoatiwecpsfigchrmbtldocttfgvqyicvkei...
output:
767010576
result:
ok 1 number(s): "767010576"
Extra Test:
score: 0
Extra Test Passed