結果
| 問題 |
No.2388 At Least K-Characters
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-07-17 15:31:47 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,138 bytes |
| コンパイル時間 | 75 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 14,464 KB |
| 最終ジャッジ日時 | 2024-07-05 03:38:16 |
| 合計ジャッジ時間 | 86,397 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 TLE * 11 |
コンパイルメッセージ
Syntax OK
ソースコード
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