結果

問題 No.2388 At Least K-Characters
ユーザー planesplanes
提出日時 2023-07-22 09:41:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,020 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 175,364 KB
実行使用メモリ 129,244 KB
最終ジャッジ日時 2023-09-18 13:05:41
合計ジャッジ時間 7,910 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 21 ms
4,380 KB
testcase_14 AC 16 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;

const int mod = 998244353;

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

const int MOD = 998244353;
vector<mint> fact, fact_inv, inv;

void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i ;
        inv[i] =  - inv[MOD % i] * (MOD / i) +MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] ;
    }
}


mint nCk(int n, int k) {
    if((n < k)) return 0;
     if ((n < 0 || k < 0)) return 0;
    return fact[n] * (fact_inv[k] * fact_inv[n - k] );
}



int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);


ll N,M,K;cin>>N>>M>>K;
string S;cin>>S;

init_nCk(100);

vector<vector<mint>> dp(M+10,vector<mint> (27,0LL));

dp[M][0]=1;
for(ll i=M-1;i>=0;i--) {
  for(ll j=1;j<=26;j++) {
    dp[i][j]+=dp[i+1][j-1]*j+dp[i+1][j]*j;
  }
}

for(ll i=M-1;i>=0;i--) {
  for(ll j=0;j<=26;j++) {
    dp[i][j]+=dp[i+1][j];
  }
}



mint ans=0;

ll count=0;
vector<bool> note(26);

for(ll i=0;i<N;i++) {
ll k=S[i]-'a';

ll up=0;
ll down=0;
for(ll j=0;j<k;j++) {
  if(!note[j]) up++;
  else down++;
}


for(ll j=0;j<=26;j++) {
  for(ll h=0;h<=j;h++) {
    if(j-h>count+1||count+1+h<K) {}
    else{
  
  ll noko=26-count-1;
  ans+=dp[i+1][j]*nCk(noko,h)*nCk(count+1,j-h)*up;
    }

 if(j-h>count||count+h<K){}
 else {
  ll noko=26-count;
  ans+=dp[i+1][j]*nCk(noko,h)*nCk(count,j-h)*down;
  }
  }
}




if(!note[k]) {
  note[k]=true;
  count++;
}

if(count>=K&&i<N-1) {
  ans+=1;
}



}


cout<<ans<<endl;
}





0