問題一覧 > 通常問題

No.2021 Not A but B

レベル : / AI推定難易度 : 650 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 185
作問者 : milkcoffee / テスター : first_vil
お気に入りにしたユーザー ProblemId : 7969 / 自分の提出
問題文最終更新日: 2022-07-27 14:39:01
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 354 (オムニバス) (順位表) の他の問題:

Problem Statement

You are given a string $S$ of length $N$ consisting of A, B. You perform the following operation on $S$ exactly $1$ time.

  • Choose $2$ consecutive characters of $S$, and replace both of those $2$ characters with B.

  • How many strings are possible as the string $S$ after the operation?

    Input

    $N$
    $S$
    

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

    Print, as an integer, the number of distinct strings $S$ that are possible as $S$ after the operation.

    Sample

    Sample 1
    Input
    4
    AABA
    
    Output
    3
    

    The following $3$ strings are possible.
    BBBA
    ABBA
    AABB

    Sample 2
    Input
    3
    ABB
    
    Output
    2
    

    The following $2$ strings are possible.
    BBB
    ABB

    Sample 3
    Input
    7
    ABABABA
    
    Output
    4
    

    The following $4$ strings are possible.
    BBABABA
    ABBBABA
    ABABBBA
    ABABABB

    Sample 4
    Input
    40
    ABBAABABAAABABBAABABAAABAAABBABAAAABBABA
    
    Output
    31
    

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