結果

問題 No.2388 At Least K-Characters
ユーザー 👑 MizarMizar
提出日時 2023-07-13 02:46:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 4,000 ms
コード長 1,559 bytes
コンパイル時間 3,274 ms
コンパイル使用メモリ 80,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 12:50:53
合計ジャッジ時間 4,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 93 ms
4,380 KB
testcase_17 AC 75 ms
4,380 KB
testcase_18 AC 97 ms
4,380 KB
testcase_19 AC 98 ms
4,380 KB
testcase_20 AC 102 ms
4,380 KB
testcase_21 AC 106 ms
4,380 KB
testcase_22 AC 105 ms
4,380 KB
testcase_23 AC 106 ms
4,376 KB
testcase_24 AC 103 ms
4,380 KB
testcase_25 AC 99 ms
4,380 KB
testcase_26 AC 104 ms
4,380 KB
testcase_27 AC 103 ms
4,380 KB
testcase_28 AC 105 ms
4,376 KB
testcase_29 AC 102 ms
4,380 KB
testcase_30 AC 101 ms
4,376 KB
testcase_31 AC 99 ms
4,376 KB
testcase_32 AC 98 ms
4,384 KB
testcase_33 AC 99 ms
4,380 KB
testcase_34 AC 104 ms
4,384 KB
testcase_35 AC 106 ms
4,380 KB
testcase_36 AC 104 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <array> // array, swap
#include <bit> // (C++20) popcount
#include <cstdlib> // abort
#include <iostream> // cin, cout, endl
#include <string> // string

#define MOD 998244353
#define KMAX 26

using ull = unsigned long long;

int main() {
	ull n, m, k;
	std::string s;
	std::cin >> n >> m >> k >> s;
	
    if(n < 1 || n > m || m > 500000 || s.length() != n || k < 1 || k > KMAX) {
        std::abort();
    }

	ull kbits = 0, result = 0;
	std::array<ull, KMAX> dp, ndp;
	dp.fill(0);

	for(auto it = s.begin(); it != s.end(); it++) {
		ull ci = *it - 'a';
		if(ci >= KMAX) {
		    std::abort;
		}
		ndp.fill(0);
		for(ull j = 0; j < ci; j++) {
			ndp[std::popcount(kbits | (1 << j)) - 1] += 1;
		}
		kbits |= (1 << ci);
		if(std::popcount(kbits) >= k) {
			result += 1;
		}
		for(ull j = 1; j < KMAX; j++) {
			ndp[j - 1] += j * dp[j - 1];
			ndp[j] += (KMAX - j) * dp[j - 1];
		}
		ndp[KMAX - 1] += KMAX * dp[KMAX - 1];
		for(ull j = 0; j < KMAX; j++) {
			ndp[j] %= MOD;
		}
		for(ull j = k - 1; j < KMAX; j++) {
			result += ndp[j];
		}
		result %= MOD;
		std::swap(dp, ndp);
	}

	if(std::popcount(kbits) >= k) {
		result = (result + (MOD - 1)) % MOD;
	}

	for(ull i = n; i < m; i++) {
		ndp.fill(0);
		for(ull j = 1; j < KMAX; j++) {
			ndp[j - 1] += j * dp[j - 1];
			ndp[j] += (KMAX - j) * dp[j - 1];
		}
		ndp[KMAX - 1] += KMAX * dp[KMAX - 1];
		for(ull j = 0; j < KMAX; j++) {
			ndp[j] %= MOD;
		}
		for(ull j = k - 1; j < KMAX; j++) {
			result += ndp[j];
		}
		result %= MOD;
		std::swap(dp, ndp);
	}
	
	std::cout << result << std::endl;
}
0