結果
| 問題 | No.2388 At Least K-Characters |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-01-08 12:42:25 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,743 bytes |
| 記録 | |
| コンパイル時間 | 313 ms |
| コンパイル使用メモリ | 82,480 KB |
| 実行使用メモリ | 115,824 KB |
| 最終ジャッジ日時 | 2026-01-08 12:42:33 |
| 合計ジャッジ時間 | 8,151 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 9 WA * 4 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:
# 使った文字を末尾に置く
yield (m, True), v * m
if m < 26:
# 未使用の文字を末尾に置く
yield (m+1, True), v * (26 - m)
if m >= K:
ans += v * m
if m+1 >= K:
ans += v * (26 - m)
ans %= MOD
elif p < len(kinds):
# 文字 x より小さい文字を置く
for c in ascii_lowercase:
if c >= S[p]: break
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
if nm >= K:
ans += v
ans %= MOD
# not lt を維持
nm = kinds[p][0]
yield (nm, 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()
kinds = []
b = 0
cnt = 0
for c in S:
k = ord(c) - ord('a')
if not (b & (1 << k)):
cnt += 1
b |= 1 << k
kinds.append((cnt, b))
ans = 0
digit_dp()
print(ans)
norioc