No.3458 Scores of Subsequence
タグ : / 解いたユーザー数 84
作問者 :
くらげ
/ テスター :
hikikomori
Problem Statement
For a string $T$, define the score $f(T)$ as follows.
- If, for some non-negative integer $N$, $T$ is formed by concatenating $N$ copies of
Mand $1$ copy ofAin this order, then $f(T) = 2^N$. - Otherwise, $f(T) = 0$.
For example, MMA is the concatenation of $2$ copies of M and $1$ copy of A in this order, so the score $f($ MMA $)$ is $4$.
You are given a string $S$ consisting only of M and A. Find the score of every subsequence of $S$, and compute their sum modulo $998244353$.
Here, a subsequence is a string obtained by removing $0$ or more characters from the original string and concatenating the remaining characters in their original order.
Constraints
- $1 \le |S| \le 2 \times 10^5$
- $S$ is a string consisting only of
MandA.
Input
$S$
Output
Print the sum of the scores of all subsequences of $S$, modulo $998244353$, in $1$ line.
Sample
Sample 1
Input
MA
Output
3
The subsequences of MA are the $3$ strings M, A, and MA, whose scores are $0$, $1$, and $2$ respectively, so the answer is $3$ since $0+1+2=3$.
Sample 2
Input
MMMAMMA
Output
270
Among the subsequences of $S = $ MMMAMMA, those with a score of $1$ or more include A, MMA, and MMMMA, with $f($A$) = 1$, $f($MMA$) = 4$, and $f($MMMMA$) = 16$.
Sample 3
Input
MAMMMAMAMMMMMAMMMMMMMMAMMAMMMA
Output
189496499
Note that you should print the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。