結果

問題 No.2021 Not A but B
ユーザー moharan627moharan627
提出日時 2022-07-29 22:21:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 77,156 KB
最終ジャッジ日時 2023-09-26 21:37:17
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,412 KB
testcase_01 AC 94 ms
71,648 KB
testcase_02 AC 94 ms
71,800 KB
testcase_03 AC 94 ms
71,596 KB
testcase_04 AC 91 ms
71,564 KB
testcase_05 AC 91 ms
71,716 KB
testcase_06 AC 92 ms
71,884 KB
testcase_07 AC 93 ms
71,576 KB
testcase_08 AC 114 ms
76,640 KB
testcase_09 AC 115 ms
76,800 KB
testcase_10 AC 113 ms
76,652 KB
testcase_11 AC 112 ms
77,064 KB
testcase_12 AC 112 ms
76,796 KB
testcase_13 AC 112 ms
76,844 KB
testcase_14 AC 114 ms
76,996 KB
testcase_15 AC 114 ms
76,632 KB
testcase_16 AC 114 ms
76,904 KB
testcase_17 AC 111 ms
76,864 KB
testcase_18 AC 112 ms
76,872 KB
testcase_19 AC 113 ms
77,016 KB
testcase_20 AC 112 ms
76,852 KB
testcase_21 AC 104 ms
76,948 KB
testcase_22 AC 105 ms
76,996 KB
testcase_23 AC 105 ms
77,156 KB
testcase_24 AC 101 ms
76,692 KB
testcase_25 AC 106 ms
76,996 KB
testcase_26 AC 107 ms
76,616 KB
testcase_27 AC 108 ms
76,808 KB
testcase_28 AC 107 ms
76,776 KB
testcase_29 AC 104 ms
77,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    N = II()
    S = input()
    Ans = 0
    BB = 0
    for i in range(N-1):
        if((S[i]=="A" and S[i+1]=="A") or (S[i]!=S[i+1])):
            Ans += 1
        elif((S[i]=="B" and S[i+1]=="B")):
            BB=1
    for i in range(N-2):
        if(S[i:i+3]=="BAB"):
            Ans-=1
    print(Ans+BB)
    return
solve()
0