QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53528 | #4475. 重复 | not_so_organic | 100 ✓ | 3ms | 3864kb | C++ | 784b | 2022-10-05 13:07:41 | 2022-10-05 13:07:43 |
Judging History
answer
#include <bits/stdc++.h>
const int mod = 998244353;
using namespace std;
int n, m, p, k, q;
int dp[5010];
char s[5010];
int ksm(int a, int k) {
int ans = 1;
for (; k; k >>= 1, a = 1ll * a * a % mod)
if (k & 1)
ans = 1ll * ans * a % mod;
return ans;
}
int main() {
scanf("%d%s", &m, s + 1);
n = strlen(s + 1);
n = min(n, m);
int i, j;
for (i = 1, j = 2; j <= n && s[i] <= s[j]; j++)
s[i] < s[j] ? i = 1 : i++;
n = j - i, s[n]--;
dp[0] = 1;
for (i = 1; i <= m; i++) {
for (j = 1; j <= min(i, n); j++) {
dp[i] = (dp[i] + 1ll * ('z' - s[j]) * dp[i - j] % mod * (i < m ? 1 : j)) % mod;
}
}
printf("%d\n", (ksm(26, m) - dp[m] + mod) % mod);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 3ms
memory: 3784kb
input:
5 utxpwmyovh
output:
11873600
result:
ok 1 number(s): "11873600"
Test #2:
score: 10
Accepted
time: 2ms
memory: 3776kb
input:
30 bhekhtazrdskusizkimkthaelctvab
output:
690391422
result:
ok 1 number(s): "690391422"
Test #3:
score: 10
Accepted
time: 2ms
memory: 3776kb
input:
50 flfsflfsflfsflfsflfs
output:
158554587
result:
ok 1 number(s): "158554587"
Test #4:
score: 10
Accepted
time: 2ms
memory: 3864kb
input:
85 ctiqhwibrrljvrsogddkjxtsoucmtqjducznwvslnjkpyjvamdnknyxslwowmewhcwkdqymljsshwljpandxjmswqukroyaydve
output:
767635094
result:
ok 1 number(s): "767635094"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3816kb
input:
193 mtkbajqtvduekczyzxrbtkqikjzclxxmaqrntemikivczxlieyqpuwkkofoltttjtbmknbkxqhepnkvmgiwxwwravldcghnhrxlfbjgutuatjgkunafziudxvfzgarytoandeepptetgbfobufwdrfssqprtolqaubdagfgxkeqpcojrhthdgzswhidcnlnbf
output:
834222930
result:
ok 1 number(s): "834222930"
Test #6:
score: 10
Accepted
time: 2ms
memory: 3864kb
input:
300 gpqfkteejltpewqtpwxjdopigynimneadkrgdzbvdteebapyvwesbsqhgofqhlfxemrxykjzbiaqgcmuoopmrnbgcgzqjenpecjcainzisqdyqvqqulprhopucebwhlsilmnhzvjwxvjqsmgdmhwrefyugibvwxnixdmpfhwrtpnrltdcwctpcvccplfbtifipqnwnbf
output:
772953201
result:
ok 1 number(s): "772953201"
Test #7:
score: 10
Accepted
time: 2ms
memory: 3816kb
input:
300 oyczstbzwdszrmnxmledokfkvddpyfaodutuzogvlisopudyvohaxxonfcgcrhbsulufholejrspjxckplrqhrencahhiaqaounemkxvhzheangultnezzhtvaousltkauurapfgvvfhvradwkykqilhupxwtqutdqfsxmtfmzdddcxljxbmchsmrgpnysnuqparmrepgzuzpbiosfbabmawjpxpvzczlzfmntuvvcftgozdntwbdmrkvvxfvqkghvbdcguuoesvpxuyzapqbsdyhoddvfzvoptsjihq...
output:
251633039
result:
ok 1 number(s): "251633039"
Test #8:
score: 10
Accepted
time: 0ms
memory: 3680kb
input:
880 abelngddxylbyvkgrsbpdegqwohgshsrtxlxuwhgstkvzfeiqrjbopwwxiudovarjhxkdoewrbwcxfliemxsggkzvpfmlkeimsejvqhocmhpvimcpvwhtlqopvfngwnrmuwwjetcagedcgdwpjglpvyotlerqbaepbgbesbxqdnwckudhjfdhbqogohaireinbczffglyghnsvptzdurzwofybpjrzopkfxnlnmtaiqjnmbfuyjpcxtwicwxrovqixxqbsrzsqhzekzkyezwdsgxwdackzdrupfyyoct...
output:
893745577
result:
ok 1 number(s): "893745577"
Test #9:
score: 10
Accepted
time: 2ms
memory: 3800kb
input:
1998 bggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwtbggcffqwwt
output:
758188091
result:
ok 1 number(s): "758188091"
Test #10:
score: 10
Accepted
time: 0ms
memory: 3784kb
input:
2000 lvcmwzggyrdooanqnloalpaiuphxpfrozonodonneognbfgyzlumraoqbtstrpesciausnzqaiwxougtwohptrakhmujgdrahfewscrcdxycrtjenzvycwehnuovgbjdipjzaoiimehrpaxzhzqbnlbaigyzpwjppikbaqrcxwwvtyuuadmyadhmrdmaockaoocetpuavaveanykqfvsmixjwijumyjucltbzqfsefvrpjrnyotjhatirvgbeygxoiweoatiwecpsfigchrmbtldocttfgvqyicvkei...
output:
767010576
result:
ok 1 number(s): "767010576"
Extra Test:
score: 0
Extra Test Passed