結果

問題 No.2388 At Least K-Characters
ユーザー 👑 timitimi
提出日時 2024-02-16 19:20:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 777 ms / 4,000 ms
コード長 986 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,352 KB
最終ジャッジ日時 2024-02-16 19:21:16
合計ジャッジ時間 17,099 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 48 ms
64,100 KB
testcase_03 AC 34 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 32 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 34 ms
53,460 KB
testcase_08 AC 33 ms
53,460 KB
testcase_09 AC 34 ms
53,460 KB
testcase_10 AC 35 ms
53,460 KB
testcase_11 AC 36 ms
53,460 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 AC 63 ms
74,156 KB
testcase_14 AC 68 ms
76,204 KB
testcase_15 AC 73 ms
76,232 KB
testcase_16 AC 604 ms
76,980 KB
testcase_17 AC 642 ms
76,956 KB
testcase_18 AC 647 ms
76,988 KB
testcase_19 AC 680 ms
77,300 KB
testcase_20 AC 689 ms
76,984 KB
testcase_21 AC 722 ms
76,980 KB
testcase_22 AC 777 ms
76,984 KB
testcase_23 AC 712 ms
76,980 KB
testcase_24 AC 707 ms
76,980 KB
testcase_25 AC 631 ms
76,984 KB
testcase_26 AC 693 ms
76,980 KB
testcase_27 AC 671 ms
76,984 KB
testcase_28 AC 725 ms
76,980 KB
testcase_29 AC 689 ms
76,980 KB
testcase_30 AC 642 ms
76,980 KB
testcase_31 AC 661 ms
76,980 KB
testcase_32 AC 697 ms
76,988 KB
testcase_33 AC 635 ms
76,988 KB
testcase_34 AC 746 ms
76,984 KB
testcase_35 AC 731 ms
77,004 KB
testcase_36 AC 721 ms
77,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K=map(int, input().split())
S=input()
dp=[[0]*2 for i in range(28)]
dp[0][0]=1;T=[0]*26 

ans=0;mod=998244353
for j in range(N):
  ss=S[j]
  ndp=[[0]*2 for _ in range(28)]
  s=ord(ss)-ord('a')
  for i in range(27):
    ndp[i][1]+=dp[i][1]*i
    ndp[i][1]%=mod
    ndp[i+1][1]+=dp[i][1]*(26-i)
    ndp[i+1][1]%=mod
  t=sum(T)
  for i in range(s):
    if T[i]==0:
      ndp[t+1][1]+=dp[t][0]
      ndp[t+1][1]%=mod
    else:
      ndp[t][1]+=dp[t][0]
      ndp[t][1]%=mod
  if T[s]==0:
    ndp[t+1][0]+=dp[t][0]
    ndp[t+1][0]%=mod
  else:
    ndp[t][0]+=dp[t][0]
    ndp[t][0]%=mod
  T[s]=1
  dp=ndp
  for i in range(K,27):
    ans+=dp[i][0]
    ans+=dp[i][1]
    ans%=mod

for _ in range(M-N):
  ndp=[[0]*2 for _ in range(28)]
  for i in range(27):
    ndp[i][1]+=dp[i][1]*i
    ndp[i][1]%=mod
    ndp[i+1][1]+=dp[i][1]*(26-i)
    ndp[i+1][1]%=mod
  dp=ndp 
  for i in range(K,27):
    ans+=dp[i][0]
    ans+=dp[i][1]
    ans%=mod

if sum(T)>=K:
  ans-=1 
  ans%=mod 
print(ans)
  
0