結果

問題 No.2388 At Least K-Characters
ユーザー kotatsugamekotatsugame
提出日時 2023-07-21 21:37:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 4,000 ms
コード長 831 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 67,816 KB
実行使用メモリ 5,728 KB
最終ジャッジ日時 2023-09-18 12:51:50
合計ジャッジ時間 4,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 101 ms
5,672 KB
testcase_17 AC 91 ms
5,656 KB
testcase_18 AC 103 ms
5,684 KB
testcase_19 AC 103 ms
5,696 KB
testcase_20 AC 107 ms
5,692 KB
testcase_21 AC 116 ms
5,664 KB
testcase_22 AC 115 ms
5,696 KB
testcase_23 AC 115 ms
5,716 KB
testcase_24 AC 109 ms
5,644 KB
testcase_25 AC 103 ms
5,716 KB
testcase_26 AC 111 ms
5,724 KB
testcase_27 AC 110 ms
5,716 KB
testcase_28 AC 113 ms
5,716 KB
testcase_29 AC 108 ms
5,636 KB
testcase_30 AC 106 ms
5,688 KB
testcase_31 AC 105 ms
5,636 KB
testcase_32 AC 103 ms
5,728 KB
testcase_33 AC 103 ms
5,696 KB
testcase_34 AC 111 ms
5,720 KB
testcase_35 AC 115 ms
5,716 KB
testcase_36 AC 111 ms
5,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N,M,K;
string S;
int ex[5<<17];
mint dp[2][27];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M>>K>>S;
	for(int i=0;i<M;i++)
	{
		ex[i+1]=ex[i];
		if(i<N)ex[i+1]|=1<<S[i]-'a';
	}
	mint ans=0;
	int now=0;
	for(int i=0;i<M;i++)
	{
		int nxt=1-now;
		for(int j=0;j<=26;j++)dp[nxt][j]=0;
		if(i<N)
		{//less
			int up=S[i]-'a';
			for(int k=0;k<up;k++)
			{
				dp[nxt][__builtin_popcount(ex[i]|1<<k)]++;
			}
		}
		for(int j=0;j<=26;j++)
		{
			dp[nxt][j]+=dp[now][j]*mint::raw(j);
			if(j<26)dp[nxt][j+1]+=dp[now][j]*mint::raw(26-j);
		}
		now=nxt;
		for(int k=K;k<=26;k++)ans+=dp[now][k];
	}
	for(int i=0;i<N&&i<M;i++)if(__builtin_popcount(ex[i])>=K)ans++;
	cout<<ans.val()<<endl;
}
0