結果

問題 No.2388 At Least K-Characters
ユーザー planesplanes
提出日時 2023-07-22 10:07:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 4,000 ms
コード長 3,039 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 175,508 KB
実行使用メモリ 124,852 KB
最終ジャッジ日時 2023-09-18 13:05:46
合計ジャッジ時間 9,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 286 ms
124,664 KB
testcase_17 AC 277 ms
124,708 KB
testcase_18 AC 286 ms
124,736 KB
testcase_19 AC 288 ms
124,756 KB
testcase_20 AC 290 ms
124,852 KB
testcase_21 AC 290 ms
124,724 KB
testcase_22 AC 287 ms
124,668 KB
testcase_23 AC 287 ms
124,612 KB
testcase_24 AC 287 ms
124,664 KB
testcase_25 AC 286 ms
124,796 KB
testcase_26 AC 288 ms
124,768 KB
testcase_27 AC 286 ms
124,668 KB
testcase_28 AC 291 ms
124,672 KB
testcase_29 AC 288 ms
124,688 KB
testcase_30 AC 287 ms
124,756 KB
testcase_31 AC 291 ms
124,684 KB
testcase_32 AC 290 ms
124,616 KB
testcase_33 AC 289 ms
124,692 KB
testcase_34 AC 289 ms
124,736 KB
testcase_35 AC 289 ms
124,668 KB
testcase_36 AC 293 ms
124,664 KB
権限があれば一括ダウンロードができます

ソースコード

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];
  }
}


vector<vector<mint>> memo(30,vector<mint> (30));

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++) {
  memo[count][j]+=dp[i+1][j]*down;
  memo[count+1][j]+=dp[i+1][j]*up;
}
 
if(!note[k]) {
  note[k]=true;
  count++;
}

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


for(ll i=1;i<=26;i++) {
  for(ll j=0;j<=26;j++) {
    for(ll h=0;h<=j;h++) {
      if(i+h<K||i<j-h) continue;
    
    ans+=memo[i][j]*nCk(26-i,h)*nCk(i,j-h);
    }
  }
}


cout<<ans<<endl;
}





0