結果

問題 No.2388 At Least K-Characters
ユーザー 👑 MizarMizar
提出日時 2023-07-17 15:31:47
言語 Ruby
(3.3.0)
結果
AC  
実行時間 3,963 ms / 4,000 ms
コード長 1,138 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 11,580 KB
実行使用メモリ 18,372 KB
最終ジャッジ日時 2023-09-18 12:50:55
合計ジャッジ時間 77,990 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,256 KB
testcase_01 AC 79 ms
15,172 KB
testcase_02 AC 79 ms
15,288 KB
testcase_03 AC 79 ms
15,192 KB
testcase_04 AC 78 ms
15,160 KB
testcase_05 AC 77 ms
15,232 KB
testcase_06 AC 77 ms
15,352 KB
testcase_07 AC 78 ms
15,328 KB
testcase_08 AC 78 ms
15,288 KB
testcase_09 AC 78 ms
15,320 KB
testcase_10 AC 79 ms
15,120 KB
testcase_11 AC 78 ms
15,244 KB
testcase_12 AC 78 ms
15,160 KB
testcase_13 AC 93 ms
15,480 KB
testcase_14 AC 91 ms
15,376 KB
testcase_15 AC 91 ms
15,668 KB
testcase_16 AC 3,263 ms
17,924 KB
testcase_17 AC 3,912 ms
18,064 KB
testcase_18 AC 3,169 ms
18,128 KB
testcase_19 AC 3,158 ms
18,112 KB
testcase_20 AC 3,525 ms
18,184 KB
testcase_21 AC 3,963 ms
18,004 KB
testcase_22 AC 3,863 ms
18,088 KB
testcase_23 AC 3,903 ms
18,284 KB
testcase_24 AC 3,677 ms
17,912 KB
testcase_25 AC 3,113 ms
18,240 KB
testcase_26 AC 3,719 ms
18,196 KB
testcase_27 AC 3,672 ms
18,332 KB
testcase_28 AC 3,819 ms
18,012 KB
testcase_29 AC 3,555 ms
18,088 KB
testcase_30 AC 3,440 ms
17,868 KB
testcase_31 AC 3,293 ms
17,992 KB
testcase_32 AC 3,162 ms
18,372 KB
testcase_33 AC 3,155 ms
18,012 KB
testcase_34 AC 3,712 ms
18,124 KB
testcase_35 AC 3,910 ms
17,860 KB
testcase_36 AC 3,720 ms
17,924 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))
	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] = (ndp[j] + j * dp[j]) % MODULO
		ndp[j + 1] += (KMAX - j) * dp[j]
	end
	(k..KMAX).each do |j|
		result += ndp[j]
	end
	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] = (ndp[j] + j * dp[j]) % MODULO
		ndp[j + 1] += (KMAX - j) * dp[j]
	end
	(k..KMAX).each do |j|
		result += ndp[j]
	end
	dp = ndp
end

puts result % MODULO
0