AtCoder Grand Contest 055
翻译中…
Problem Statement
翻译中…
Let's call a string $T$ of length $3N$, containing exactly $N$ letters A, $N$ letters B, and $N$ letters C, good, if it can be split into $N$ (not necessarily contiguous) subsequences of length $3$, so that the letters from each subsequence form ABC, BCA, or CAB.
翻译中…
You are given a string $S$ of length $3N$, consisting of characters A, B, C, and ?. Count the number of ways to replace each ? with one of A, B, and C, so that the resulting string is good. As this number can be very large, output it modulo $998244353$.
翻译中…
Constraints
翻译中…
$1\le N \le 15$.$S$is a string of length$3N$, consisting ofA,B,C, and?.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
S
翻译中…
Output
翻译中…
Print the answer modulo $998244353$.
翻译中…
样例
Input #1
1
???
Output #1
3
There are $3$ good strings you can obtain: `ABC`, `BCA`, and `CAB`.
Input #2
2
AA????
Output #2
2
There are $2$ good strings you can obtain: `AABBCC` and `AABCBC`.
Input #3
3
?A?A?A?A?
Output #3
0
It's impossible to obtain a good string, as there are already $4$ `A`'s.
Input #4
9
?????????A??B??C???????????
Output #4
331653164
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。