No.2276 I Want AC
Problem Statement
You are given a string $S$ of length $N$ consisting of A, C, and ?.
You perform the following operation on $S$.
- Replace each
?in $S$ with eitherAorC.
After the operation, the score is the number of ways to extract AC as a (not necessarily contiguous) subsequence from $S$. Here, two ways of extracting a subsequence are considered different if the extracted positions are different.
Find the maximum possible score.
Input
$N$ $S$
- $N$ is an integer.
- $2 \leq N \leq 2 \times 10^5$
- $S$ is a string of length $N$ consisting of
A,C, and?.
Output
Output the maximum possible score, followed by a newline.
Sample
Sample 1
Input
5 A?CA?
Output
5
For example, if we make $S = $ AACAC, the ways to extract the (not necessarily contiguous) subsequence AC from $S$ are the following
- Extract the $1$-st and $3$-rd characters
- Extract the $1$-st and $5$-th characters
- Extract the $2$-nd and $3$-rd characters
- Extract the $2$-nd and $5$-th characters
- Extract the $4$-th and $5$-th characters
The other strings $S$ possible after the operation and their scores are as follows.
- If $S = $
AACAA, the score is $2$. - If $S = $
ACCAA, the score is $2$. - If $S = $
ACCAC, the score is $4$.
AACAC achieves the maximum value $5$.
Sample 2
Input
6 ACACAC
Output
6
$S$ may contain no ?.
Sample 3
Input
10 ??????????
Output
25
Making $S = $ AAAAACCCCC is optimal.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
miscalc
magsta