結果

問題 No.2388 At Least K-Characters
ユーザー kwm_tkwm_t
提出日時 2023-07-21 22:33:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,294 bytes
コンパイル時間 5,051 ms
コンパイル使用メモリ 269,660 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 12:55:57
合計ジャッジ時間 14,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 2,211 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 266 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 509 ms
4,384 KB
testcase_10 AC 276 ms
4,380 KB
testcase_11 AC 358 ms
4,376 KB
testcase_12 AC 195 ms
4,380 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
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>
#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;
}
0