結果

問題 No.2388 At Least K-Characters
ユーザー t98slider
提出日時 2023-07-22 00:31:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 4,000 ms
コード長 817 bytes
コンパイル時間 4,434 ms
コンパイル使用メモリ 230,588 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 04:11:38
合計ジャッジ時間 6,722 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    string s;
    cin >> n >> m >> k >> s;
    int S = 0;
    mint ans;
    array<mint, 27> dp;
    for(int i = 0; i < m; i++){
        dp[26] *= 26;
        for(int j = 25; j >= 1; j--){
            dp[j + 1] += (26 - j) * dp[j];
            dp[j] *= j;
        }
        if(i < n){
            const int d = s[i] - 'a';
            for(int j = 0; j < d; j++){
                dp[__builtin_popcount(S | (1 << j))]++;
            }
            S |= 1 << d;
            if(i + 1 < n && __builtin_popcount(S) >= k) ans++;
        }
        ans += accumulate(dp.begin() + k, dp.end(), mint(0));
    }
    cout << ans.val() << '\n';
}
0