結果

問題 No.2388 At Least K-Characters
ユーザー Nzt3
提出日時 2023-07-22 23:38:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 253 ms / 4,000 ms
コード長 838 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 202,532 KB
最終ジャッジ日時 2025-02-15 18:15:56
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int mod=998244353;
void ch(ll &a,ll b){
  a=(a+b)%mod;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M,K;
  cin>>N>>M>>K;
  string S;
  cin>>S;
  vector<vector<ll>>dp(M+1,vector<ll>(27));
  set<char>sd;

  ll ans=0;
  for(int i=0;i<M;i++){
    for(int j=0;j<=26;j++){
      ch(dp[i+1][j],dp[i][j]*j);
    }
    for(int j=0;j<26;j++){
      ch(dp[i+1][j+1],dp[i][j]*(26-j));
    }
    if(i<N){
      for(int j='a';j<S[i];j++){
        if(sd.find(j)==sd.end()){
          ch(dp[i+1][sd.size()+1],1);
        }else{
          ch(dp[i+1][sd.size()],1);
        }
      }
      if(sd.size()>=K)++ans;
      sd.insert(S[i]);
    }
  }
  for(int i=0;i<=M;i++){
    for(int j=K;j<=26;j++){
      ch(ans,dp[i][j]);
    }
  }
  cout<<ans<<'\n';
}
0