結果
| 問題 | No.2388 At Least K-Characters |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2023-07-21 22:33:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,294 bytes |
| 記録 | |
| コンパイル時間 | 4,126 ms |
| コンパイル使用メモリ | 261,352 KB |
| 最終ジャッジ日時 | 2025-02-15 17:08:36 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 23 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
vector<vector<T>> mul(vector<vector<T>>&A, vector<vector<T>>&B) {
vector<vector<T>> C(A.size(), vector<T>(B[0].size()));
rep(i, A.size()) rep(j, B[0].size()) rep(k, A[0].size()) C[i][j] += A[i][k] * B[k][j];
return C;
}
mint calc(int sz, int kind, int k) {
vector<vector<mint>> mans(54, vector<mint>(54));
rep(i, 54)mans[i][i] = 1;
vector<vector<mint>> mpow(54, vector<mint>(54));
rep(i, 27)mpow[i + 0][i] = i;
rep(i, 27)mpow[i + 1][i] = 26 - i;
rep(i, 27)mpow[27 + i][i] = 1;
rep(i, 27)mpow[27 + i][27 + i] = 1;
//mpow初期化
while (sz > 0) {
if (1 == sz % 2) mans = mul(mpow, mans);
mpow = mul(mpow, mpow);
sz /= 2;
}
mint ret = 0;
rep2(i, k, 27) {
ret += mans[i][kind];
ret += mans[i + 27][kind];
}
return ret;
}
mint TLE(int sz, int kind, int k) {
vector dp(sz + 1, vector<mint>(27));
dp[0][kind] = 1;
rep(i, sz) {
rep(j, 27) {
dp[i + 1][j] += dp[i][j] * j;
dp[i + 1][j + 1] += dp[i][j] * (26 - j);
}
}
mint ret = 0;
rep(i, sz + 1) rep2(j, k, 27) {
ret += dp[i][j];
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k; cin >> n >> m >> k;
string s; cin >> s;
set<char>st;
mint ans = 0;
rep(i, s.size()) {
if (st.size() >= k)ans++;
int x = s[i] - 'a';
rep(j, x) {
int kind = st.size();
if (!st.count('a' + j))kind++;
int sz = m - (i + 1);
ans += calc(sz, kind, k);
}
st.insert(s[i]);
}
cout << ans.val() << endl;
return 0;
}
kwm_t