問題一覧 > 通常問題

No.1927 AB-CD

レベル : / AI推定難易度 : 900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 150
作問者 : milkcoffee / テスター : 👑 qand
お気に入りにしたユーザー ProblemId : 7878 / 自分の提出
問題文最終更新日: 2022-04-09 12:13:52
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 342 (順位表) の他の問題:

Problem Statement

You are given a string $S$ of length $N$ consisting of A,B,C,D. You may perform the following operation on $S$ any number of times.

  • Choose $2$ adjacent, different characters. However, you cannot choose AB,BA,CD,DC as the $2$ adjacent characters. Then, swap the $2$ chosen characters.

  • Find the number of strings $S$ that can be obtained by performing this operation $0$ or more times, modulo $998244353$.

    Input

    $N$
    $S$
    

  • $2 \leq N \leq 3 \times 10^5$
  • $N$ is an integer.
  • $S$ is a string of length $N$ consisting of A,B,C,D.
  • Output

    Print, as an integer, the number of possible strings $S$ after the operations, modulo $998244353$.

    Sample

    Sample 1
    Input
    3
    ABC
    Output
    3
    

    The following $3$ strings are possible as $S$ after the operations.
    ABC, ACB, CAB

    Note that A and B cannot be swapped.

    Sample 2
    Input
    6
    CCDDCC
    
    Output
    1
    

    The only possible $S$ after the operations is CCDDCC, which is $1$ string.

    Sample 3
    Input
    100
    BDBADDDACABABABDDADBBCBDBBDCBBCAAACCDBBDDAABAACDDAAACBCDABBCADAAABCCCAADBADBBCACADCACADAACBACCBADAAA
    
    Output
    472878571
    

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