結果

問題 No.2021 Not A but B
ユーザー ohanaohana
提出日時 2023-10-02 13:03:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 361 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 91,440 KB
最終ジャッジ日時 2023-10-02 13:03:48
合計ジャッジ時間 5,264 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,524 KB
testcase_01 AC 72 ms
71,636 KB
testcase_02 AC 71 ms
71,180 KB
testcase_03 AC 77 ms
71,284 KB
testcase_04 AC 73 ms
71,372 KB
testcase_05 AC 73 ms
71,300 KB
testcase_06 AC 73 ms
71,472 KB
testcase_07 AC 75 ms
71,280 KB
testcase_08 AC 144 ms
89,216 KB
testcase_09 AC 136 ms
88,812 KB
testcase_10 AC 134 ms
89,428 KB
testcase_11 AC 129 ms
88,972 KB
testcase_12 AC 130 ms
89,020 KB
testcase_13 AC 132 ms
89,592 KB
testcase_14 AC 133 ms
89,076 KB
testcase_15 AC 129 ms
89,200 KB
testcase_16 AC 130 ms
88,960 KB
testcase_17 AC 131 ms
88,904 KB
testcase_18 AC 138 ms
88,900 KB
testcase_19 AC 131 ms
89,016 KB
testcase_20 AC 132 ms
88,704 KB
testcase_21 AC 80 ms
76,672 KB
testcase_22 AC 79 ms
76,396 KB
testcase_23 AC 76 ms
76,668 KB
testcase_24 AC 76 ms
75,572 KB
testcase_25 AC 81 ms
76,600 KB
testcase_26 AC 90 ms
89,492 KB
testcase_27 AC 131 ms
91,440 KB
testcase_28 AC 131 ms
91,368 KB
testcase_29 AC 96 ms
89,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

n = int(input())
s = input()

A = [(k, len(list(g))) for k, g in itertools.groupby(s)]

ans = 0
for i in range(len(A)):
    if A[i][0] == "A":
        if A[i][1] == 1:
            ans += 1
        else:
            ans += A[i][1] + 1

ans += "BB" in s
ans -= (A[0][0] == "A" and A[0][1] != 1) + (A[-1][0] == "A" and A[-1][1] != 1)

print(ans)
0