結果

問題 No.2388 At Least K-Characters
ユーザー 👑 MizarMizar
提出日時 2023-07-17 15:18:08
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 857 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 11,316 KB
実行使用メモリ 16,712 KB
最終ジャッジ日時 2023-09-18 12:49:39
合計ジャッジ時間 45,073 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,160 KB
testcase_01 AC 82 ms
15,132 KB
testcase_02 AC 82 ms
15,324 KB
testcase_03 AC 80 ms
15,044 KB
testcase_04 AC 80 ms
15,136 KB
testcase_05 AC 79 ms
15,104 KB
testcase_06 AC 81 ms
15,084 KB
testcase_07 AC 81 ms
15,192 KB
testcase_08 AC 81 ms
15,356 KB
testcase_09 AC 81 ms
15,148 KB
testcase_10 AC 82 ms
15,340 KB
testcase_11 AC 81 ms
15,300 KB
testcase_12 AC 83 ms
15,296 KB
testcase_13 AC 101 ms
15,392 KB
testcase_14 AC 97 ms
15,144 KB
testcase_15 AC 98 ms
15,300 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 3,924 ms
16,440 KB
testcase_19 AC 3,925 ms
16,292 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 3,919 ms
16,260 KB
testcase_33 AC 3,926 ms
16,460 KB
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m, k = gets.split.map(&:to_i)
s = gets.chomp

MODULO = 998244353
KMAX = 26

kbits, kbc, result = 0, 0, 0
dp = Array.new(KMAX + 2, 0)
ndp = Array.new(KMAX + 2, 0)

s.bytes do |c|
	ci = c - "a".ord
	ndp.fill(0)
	same = (kbits & ((1 << ci) - 1)).to_s(2).count('1')
	ndp[kbc] += same
	ndp[kbc + 1] += ci - same
	if (kbits & (1 << ci)) == 0 then
		kbits |= (1 << ci)
		kbc += 1
	end
	if kbc >= k then
		result += 1
	end
	(1..KMAX).each do |j|
		ndp[j] += j * dp[j]
		ndp[j + 1] += (KMAX - j) * dp[j]
		ndp[j] %= MODULO
	end
	(k..KMAX).each do |j|
		result += ndp[j]
	end
	dp, ndp = ndp, dp
end

if kbc >= k then
	result -= 1
end

(n...m).each do |i|
	ndp.fill(0)
	(1..KMAX).each do |j|
		ndp[j] += j * dp[j]
		ndp[j + 1] += (KMAX - j) * dp[j]
		ndp[j] %= MODULO
	end
	(k..KMAX).each do |j|
		result += ndp[j]
	end
	dp, ndp = ndp, dp
end

puts result % MODULO
0