結果

問題 No.2021 Not A but B
ユーザー pitPpitP
提出日時 2022-07-29 21:47:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 457 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 79,536 KB
最終ジャッジ日時 2023-09-26 20:25:57
合計ジャッジ時間 4,159 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,960 KB
testcase_01 AC 71 ms
71,028 KB
testcase_02 AC 73 ms
71,412 KB
testcase_03 AC 72 ms
71,252 KB
testcase_04 AC 72 ms
71,280 KB
testcase_05 AC 72 ms
71,348 KB
testcase_06 AC 72 ms
71,348 KB
testcase_07 AC 72 ms
71,188 KB
testcase_08 AC 92 ms
79,304 KB
testcase_09 AC 91 ms
79,236 KB
testcase_10 AC 90 ms
79,204 KB
testcase_11 AC 90 ms
79,080 KB
testcase_12 AC 91 ms
79,164 KB
testcase_13 AC 91 ms
79,068 KB
testcase_14 AC 92 ms
79,200 KB
testcase_15 AC 90 ms
79,140 KB
testcase_16 AC 90 ms
79,260 KB
testcase_17 AC 89 ms
79,204 KB
testcase_18 AC 90 ms
79,360 KB
testcase_19 AC 92 ms
79,536 KB
testcase_20 AC 90 ms
79,200 KB
testcase_21 AC 81 ms
75,864 KB
testcase_22 AC 81 ms
75,848 KB
testcase_23 AC 81 ms
75,796 KB
testcase_24 AC 75 ms
75,568 KB
testcase_25 AC 81 ms
75,816 KB
testcase_26 AC 81 ms
79,316 KB
testcase_27 AC 86 ms
79,192 KB
testcase_28 AC 86 ms
79,052 KB
testcase_29 AC 82 ms
79,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = list(input())
boo = True
flag = True
ans = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "A":
        boo = True
        ans += 1
    elif s[i] == "B" and s[i+1] == "B":
        boo = False
        if flag :
            ans += 1
            flag = False
    elif s[i] == "B" and s[i+1] == "A":
        boo = False
        ans += 1
    else:
        if boo:
            ans += 1
        boo = True
    #print(ans,i)

print(ans)
0