結果

問題 No.2388 At Least K-Characters
ユーザー 👑 MizarMizar
提出日時 2023-07-17 15:51:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,907 ms / 4,000 ms
コード長 1,070 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 17,840 KB
最終ジャッジ日時 2023-09-18 12:52:09
合計ジャッジ時間 61,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,020 KB
testcase_01 AC 78 ms
15,300 KB
testcase_02 AC 83 ms
15,088 KB
testcase_03 AC 83 ms
15,120 KB
testcase_04 AC 77 ms
15,032 KB
testcase_05 AC 78 ms
15,160 KB
testcase_06 AC 78 ms
15,256 KB
testcase_07 AC 79 ms
15,176 KB
testcase_08 AC 78 ms
15,160 KB
testcase_09 AC 77 ms
15,016 KB
testcase_10 AC 76 ms
15,120 KB
testcase_11 AC 77 ms
15,028 KB
testcase_12 AC 77 ms
15,140 KB
testcase_13 AC 89 ms
16,044 KB
testcase_14 AC 85 ms
15,676 KB
testcase_15 AC 87 ms
15,900 KB
testcase_16 AC 2,731 ms
17,608 KB
testcase_17 AC 2,774 ms
17,784 KB
testcase_18 AC 2,566 ms
17,380 KB
testcase_19 AC 2,558 ms
17,504 KB
testcase_20 AC 2,745 ms
17,840 KB
testcase_21 AC 2,768 ms
17,776 KB
testcase_22 AC 2,777 ms
17,624 KB
testcase_23 AC 2,907 ms
17,656 KB
testcase_24 AC 2,873 ms
17,632 KB
testcase_25 AC 2,581 ms
17,400 KB
testcase_26 AC 2,778 ms
17,640 KB
testcase_27 AC 2,754 ms
17,728 KB
testcase_28 AC 2,758 ms
17,752 KB
testcase_29 AC 2,731 ms
17,628 KB
testcase_30 AC 2,747 ms
17,700 KB
testcase_31 AC 2,759 ms
17,724 KB
testcase_32 AC 2,611 ms
17,552 KB
testcase_33 AC 2,564 ms
17,584 KB
testcase_34 AC 2,841 ms
17,740 KB
testcase_35 AC 2,774 ms
17,776 KB
testcase_36 AC 2,782 ms
17,724 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

MODULO = 998244353
KMAX = 26
ORD_A = "a".ord

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

def popcount32(x)
    x = ((x & 0xaaaaaaaa) >>  1) + (x & 0x55555555)
    x = ((x & 0xcccccccc) >>  2) + (x & 0x33333333)
    x = ((x & 0xf0f0f0f0) >>  4) + (x & 0x0f0f0f0f)
    x = ((x & 0xff00ff00) >>  8) + (x & 0x00ff00ff)
    x = ((x & 0xffff0000) >> 16) + (x & 0x0000ffff)
    x
end

s.bytes do |c|
	ci = c - ORD_A
	ndp = Array.new(KMAX + 2, 0)
	same = popcount32(kbits & ((1 << ci) - 1))
	(1..KMAX).each do |j|
		ndp[j] = ((KMAX - j + 1) * dp[j - 1] + j * dp[j]) % MODULO
	end
	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
	result += ndp[k..KMAX].sum
	dp = ndp
end

if kbc >= k then
	result -= 1
end

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

puts result % MODULO
0