結果

問題 No.2021 Not A but B
ユーザー tamato
提出日時 2022-07-29 21:34:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 69,888 KB
最終ジャッジ日時 2024-07-19 13:22:26
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')

    cnt = 0
    cnt2 = 0
    for i in range(N - 1):
        if S[i] == S[i+1] == "B":
            cnt += 1
        else:
            if i + 2 < N:
                if S[i] == "B" and S[i+1] == "A" and S[i+2] == "B":
                    cnt2 += 1
    print(N - 1 - max(0, cnt - 1) - cnt2)


if __name__ == '__main__':
    main()
0