estie プログラミングコンテスト2024 (AtCoder Regular Contest 188)
A
ABC Symmetry
AtCoder
⌀ 1914
原题
←B →
翻译中…

Problem Statement

翻译中…

For a non-empty string $T$ consisting of A, B, and C, we call it a good string if it can be turned into an empty string by performing the following two types of operations any number of times in any order.

翻译中…
  • Operation $1$: Choose two identical characters in the string and delete them (cannot be performed if there are not two or more identical characters).
  • Operation $2$: Choose one A, one B, and one C in the string and delete them (cannot be performed if there are not one or more of each of A, B, and C).
翻译中…

For example, ABACA is a good string because it can be turned into an empty string by performing the operations as follows:

翻译中…
  • Choose the 2nd, 4th, and 5th characters and delete them (Operation $2$). The string becomes AA.
  • Choose the 1st and 2nd characters and delete them (Operation $1$). The string becomes an empty string.
翻译中…

You are given a string $S$ of length $N$ consisting of A, B, C, and ?. How many ways are there to replace each ? with A, B, or C to form a string that contains at least $K$ good strings as contiguous substrings? Substrings are counted separately if they are at different positions in the original string, even if they are identical strings.

翻译中…

Find the count modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 50$
  • $0 \leq K \leq \frac{N(N+1)}{2}$
  • $N$ and $K$ are integers.
  • $|S| = N$
  • $S$ is a string consisting of A, B, C, and ?.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K
S

翻译中…

Output

翻译中…

Print the answer modulo $998244353$.

翻译中…

样例

Input #1
4 2
A?AB
Output #1
1
By replacing `?` with `A`, `B`, or `C`, we can obtain the following three strings: `AAAB`, `ABAB`, `ACAB`. Among these, `AAAB` contains two good substrings: the `AA` at positions $1,2$ and the `AA` at positions $2,3$. Note that even if the substrings are identical as strings, they are counted separately if they are at different positions in the original string. On the other hand, `ABAB` contains only one good substring `ABAB`. Also, `ACAB` contains only one good substring `CAB`.
Input #2
50 411
??AB??C???????????????????????????????A???C????A??
Output #2
457279314
Print the count modulo $998244353$.
Input #3
1 0
A
Output #3
1
题目信息
题号
arc188_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。