結果

問題 No.2388 At Least K-Characters
ユーザー 👑 MizarMizar
提出日時 2023-07-15 13:37:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 4,000 ms
コード長 1,398 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 81,208 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 12:51:01
合計ジャッジ時間 3,195 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 52 ms
4,376 KB
testcase_17 AC 57 ms
4,380 KB
testcase_18 AC 52 ms
4,376 KB
testcase_19 AC 51 ms
4,376 KB
testcase_20 AC 53 ms
4,380 KB
testcase_21 AC 57 ms
4,380 KB
testcase_22 AC 57 ms
4,376 KB
testcase_23 AC 57 ms
4,380 KB
testcase_24 AC 55 ms
4,380 KB
testcase_25 AC 51 ms
4,376 KB
testcase_26 AC 56 ms
4,376 KB
testcase_27 AC 55 ms
4,376 KB
testcase_28 AC 56 ms
4,380 KB
testcase_29 AC 54 ms
4,380 KB
testcase_30 AC 53 ms
4,376 KB
testcase_31 AC 53 ms
4,376 KB
testcase_32 AC 51 ms
4,376 KB
testcase_33 AC 52 ms
4,376 KB
testcase_34 AC 56 ms
4,380 KB
testcase_35 AC 58 ms
4,380 KB
testcase_36 AC 56 ms
4,376 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
#define KMAX2 (KMAX+2)

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, kbc = 0, result = 0;
	std::array<ull, KMAX2> 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);
		ull m = std::popcount(kbits & ((1 << ci) - 1));
		ndp[kbc] += m;
		ndp[kbc + 1] += ci - m;
		if((kbits & (1 << ci)) == 0) {
			kbits |= (1 << ci);
			kbc += 1;
		}
		if(kbc >= k) {
			result += 1;
		}
		for(ull j = 1; j <= KMAX; j++) {
			ndp[j] += j * dp[j];
			ndp[j + 1] += (KMAX - j) * dp[j];
			ndp[j] %= MOD;
		}
		for(ull j = k; j <= KMAX; j++) {
			result += ndp[j];
		}
		std::swap(dp, ndp);
	}

	if(kbc >= k) {
		result -= 1;
	}

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