結果

問題 No.2388 At Least K-Characters
ユーザー FromBooskaFromBooska
提出日時 2023-07-26 18:38:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 900 ms / 4,000 ms
コード長 1,449 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 221,416 KB
最終ジャッジ日時 2023-09-18 13:08:04
合計ジャッジ時間 18,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,264 KB
testcase_01 AC 72 ms
71,492 KB
testcase_02 AC 83 ms
76,312 KB
testcase_03 AC 71 ms
71,360 KB
testcase_04 AC 73 ms
71,260 KB
testcase_05 AC 73 ms
71,328 KB
testcase_06 AC 72 ms
71,300 KB
testcase_07 AC 72 ms
71,300 KB
testcase_08 AC 72 ms
71,092 KB
testcase_09 AC 74 ms
71,184 KB
testcase_10 AC 74 ms
71,180 KB
testcase_11 AC 74 ms
71,268 KB
testcase_12 AC 74 ms
71,344 KB
testcase_13 AC 92 ms
76,616 KB
testcase_14 AC 97 ms
77,216 KB
testcase_15 AC 96 ms
77,400 KB
testcase_16 AC 633 ms
221,180 KB
testcase_17 AC 853 ms
221,184 KB
testcase_18 AC 605 ms
221,032 KB
testcase_19 AC 604 ms
221,184 KB
testcase_20 AC 721 ms
221,136 KB
testcase_21 AC 900 ms
221,192 KB
testcase_22 AC 873 ms
221,352 KB
testcase_23 AC 877 ms
221,220 KB
testcase_24 AC 779 ms
221,200 KB
testcase_25 AC 597 ms
221,284 KB
testcase_26 AC 809 ms
221,140 KB
testcase_27 AC 799 ms
221,152 KB
testcase_28 AC 851 ms
221,236 KB
testcase_29 AC 733 ms
221,228 KB
testcase_30 AC 718 ms
221,216 KB
testcase_31 AC 653 ms
221,020 KB
testcase_32 AC 598 ms
221,296 KB
testcase_33 AC 606 ms
221,416 KB
testcase_34 AC 836 ms
221,284 KB
testcase_35 AC 876 ms
221,264 KB
testcase_36 AC 801 ms
221,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 自力できず公式解説見る
# dp[i文字目までで][j種類の文字を使ったパターン数
# 遷移は、dp[i-1][j]で既に出た文字を使う場合がdp[i-1][j]*j
# もう1つが、dp[i-1][j-1]から出ていない文字が出る場合がdp[i-1][j-1]*(26-j)
# dp[i][j] = dp[i-1][j]*j + dp[i-1][j-1]*(26-j)
# 解説見ても自力実装できず人のを見る、ということは自力を超えてる

N, M, K = map(int,input().split())
S = input()
current = 0
count = [0]*26
mod = 998244353

alphabets = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for i in range(26):
    dic[alphabets[i]] = i

dp = [[0]*27 for _ in range(M+1)]

ans = 0
for i in range(N):
    s = dic[S[i]]
    for j in range(s):
        if count[j] == 0:
            dp[i+1][current+1] += 1
        else:
            dp[i+1][current] += 1
    for j in range(27):
        dp[i+1][j] += dp[i][j]*j
        if 0 < j < 26:
            dp[i+1][j+1] += dp[i][j]*(26-j)
    for j in range(27):
        dp[i+1][j] %= mod
    if count[s] == 0:
        current += 1
        count[s] +=  1
    if current >= K:
        ans += 1

for i in range(N, M):
    for j in range(1,27):
        dp[i+1][j] += dp[i][j] * j
        if 0 < j < 26:
            dp[i+1][j+1] += dp[i][j]*(26-j)
    for j in range(27):
        dp[i+1][j] %= mod

for i in range(K, 27):
    for j in range(M+1):
        ans += dp[j][i]
        ans %= mod
if current >= K:
    ans -= 1
    ans %= mod
print(ans)
0