結果
| 問題 | No.2388 At Least K-Characters |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-01-08 16:04:38 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,815 bytes |
| 記録 | |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 82,496 KB |
| 実行使用メモリ | 115,728 KB |
| 最終ジャッジ日時 | 2026-01-08 16:04:47 |
| 合計ジャッジ時間 | 8,077 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 1 -- * 20 |
ソースコード
from collections.abc import Iterable
from string import ascii_lowercase
def accum_dp(xs: Iterable, f, op, e, init: dict, *, is_reset=True):
dp = init.copy()
for x in xs:
pp = {} if is_reset else dp.copy()
dp, pp = pp, dp
for fm_key, fm_val in pp.items():
for to_key, to_val in f(fm_key, fm_val, x):
dp[to_key] = op(dp.get(to_key, e), to_val)
return dp
def f(k, v, x):
global ans
m, lt = k # (使った文字種, 未満か)
p = x
if lt:
assert m > 0
# 使った文字を末尾に置く
yield (m, True), v * m
if m < 26:
# 未使用の文字を末尾に置く
yield (m+1, True), v * (26 - m)
if m >= K:
ans += v * m
if m < 26 and m+1 >= K:
ans += v * (26 - m)
ans %= MOD
elif p < N:
# 文字 x より小さい文字を置く
for c in ascii_lowercase:
if c >= S[p]: continue
if p == 0:
nm = 0
b = 0
else:
nm, b = kinds[p-1]
if not (b & (1 << (ord(c) - ord('a')))):
nm += 1
yield (nm, True), v
assert v == 1
if nm >= K:
ans += v
ans %= MOD
if p+1 < N and kinds[p][0] >= K:
ans += 1
ans %= MOD
# not lt を維持
yield (0, False), v
def op(a, b):
return (a + b) % MOD
def digit_dp():
init = {(0, False): 1}
accum_dp(range(M), f, op, 0, init)
MOD = 998244353
N, M, K = map(int, input().split())
S = input()
st = set()
b = 0
kinds = []
for c in S:
st.add(c)
b |= (1 << (ord(c) - ord('a')))
kinds.append((len(st), b))
ans = 0
digit_dp()
print(ans)
norioc