問題一覧 > 通常問題

No.3370 AB → BA

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 18
作問者 : みどりむし🦠 / テスター : Naru820 jupiter_68 rhoo noya2
お気に入りにしたユーザー ProblemId : 12816 / 自分の提出
問題文最終更新日: 2025-11-17 12:19:21
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 作問ハッカソンコンテスト 003 Day2 (順位表) の他の問題:

Problem Statement

You are given a string $S$ consisting only of A and B.
For any string $X$, you can perform the following operation:

  • Choose one substring AB contained in $X$ and replace it with BA.
Find the number of strings that can be made equal to $S$ by performing this operation any number of times, $0$ or more.
Since the answer can be very large, output it modulo $998244353$.

Constraints

  • $1 \leq |S| \leq 4 \times 10^5$
  • $S_i \in \{$ A, B $\} \; \scriptsize (1 \leq i \leq |S|)$

Input

The input is given from standard input in the following format:
$S$

Output

Find the answer and print it modulo $998244353$ to standard output.

Sample

Sample 1
Input
BBA
Output
3

There are $3$ such strings: BBA, BAB, and ABB.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。