結果
問題 | No.2388 At Least K-Characters |
ユーザー |
![]() |
提出日時 | 2023-07-21 22:11:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 177 ms / 4,000 ms |
コード長 | 1,442 bytes |
コンパイル時間 | 4,467 ms |
コンパイル使用メモリ | 255,320 KB |
最終ジャッジ日時 | 2025-02-15 16:59:46 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } int main(){ // KETA DP // small ga kakutei siteiruka? // onaji nara? int n, m, k; cin >> n >> m >> k; string s; cin >> s; vector<mint> dp0(27); // small vector<mint> dp1(27); // not small int tmp = 0; vector<bool> snow(26); mint ans = 0; rep(num,0,m){ vector<mint> ndp0(27); // small vector<mint> ndp1(27); // not small rep(j,0,27){ if (j+1 <= 26) ndp0[j+1] += dp0[j] * (26-j); ndp0[j] += dp0[j] * j; } if (num < n){ rep(j,0,(int)(s[num] - 'a')){ if (snow[j]) ndp0[tmp]++; else ndp0[tmp+1]++; //rep(k,0,27){ // if (snow[j]) ndp0[k] += dp1[k]; // else ndp0[k+1] += dp1[k]; // } } if (snow[s[num] - 'a']) ndp1[tmp]++; else ndp1[tmp+1]++; if (!snow[s[num] - 'a']) tmp++; snow[s[num] - 'a'] = true; } dp0 = ndp0; dp1 = ndp1; rep(i,k,27){ ans += dp0[i]; if (num < n-1) ans += dp1[i]; } //cout << ans.val() << '\n'; } //if (tmp >= k) ans--; cout << ans.val() << '\n'; }