結果
| 問題 |
No.2388 At Least K-Characters
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-07-15 14:30:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 239 ms / 4,000 ms |
| コード長 | 1,067 bytes |
| コンパイル時間 | 192 ms |
| コンパイル使用メモリ | 81,664 KB |
| 実行使用メモリ | 77,056 KB |
| 最終ジャッジ日時 | 2024-07-05 03:39:03 |
| 合計ジャッジ時間 | 6,659 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
import sys
n, m, k = map(int, input().split())
s = input()
MOD = 998244353
KMAX = 26
KMAX2 = KMAX + 2
ORDA = ord('a')
kbits = 0
kbc = 0
result = 0
dp = [0] * KMAX2
if len(s) != n or n < 1 or n > m or m > 500000 or k < 1 or k > KMAX:
sys.exit(1)
for c in s:
ndp = [0] * KMAX2
ci = ord(c) - ORDA
if ci < 0 or ci >= KMAX:
sys.exit(1)
cib = 1 << ci
same = (kbits & (cib - 1)).bit_count()
ndp[kbc] += same
ndp[kbc + 1] += ci - same
if (kbits & cib) == 0:
kbits |= cib
kbc += 1
if kbc >= k:
result += 1
for j in range(1, KMAX + 1):
ndp[j] += j * dp[j]
ndp[j + 1] += (KMAX - j) * dp[j]
ndp[j] %= MOD
for j in range(k, KMAX + 1):
result += ndp[j]
dp = ndp
if kbc >= k:
result -= 1
for _ in range(n, m):
ndp = [0] * KMAX2
for j in range(1, KMAX + 1):
ndp[j] += j * dp[j]
ndp[j + 1] += (KMAX - j) * dp[j]
ndp[j] %= MOD
for j in range(k, KMAX + 1):
result += ndp[j]
dp = ndp
result %= MOD
print(result)