結果

問題 No.2021 Not A but B
ユーザー tktk_snsntktk_snsn
提出日時 2022-07-29 21:54:32
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 17,616 KB
最終ジャッジ日時 2023-09-26 20:37:25
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,824 KB
testcase_01 AC 17 ms
7,764 KB
testcase_02 AC 16 ms
7,916 KB
testcase_03 AC 16 ms
7,788 KB
testcase_04 AC 15 ms
7,808 KB
testcase_05 AC 15 ms
7,856 KB
testcase_06 AC 15 ms
7,804 KB
testcase_07 AC 15 ms
7,836 KB
testcase_08 AC 125 ms
15,480 KB
testcase_09 AC 123 ms
15,488 KB
testcase_10 AC 121 ms
15,488 KB
testcase_11 AC 122 ms
15,012 KB
testcase_12 AC 121 ms
15,144 KB
testcase_13 AC 121 ms
15,556 KB
testcase_14 AC 130 ms
15,612 KB
testcase_15 AC 126 ms
15,448 KB
testcase_16 AC 124 ms
15,552 KB
testcase_17 AC 120 ms
14,936 KB
testcase_18 AC 126 ms
15,672 KB
testcase_19 AC 125 ms
15,640 KB
testcase_20 AC 124 ms
15,532 KB
testcase_21 AC 22 ms
8,656 KB
testcase_22 AC 19 ms
8,304 KB
testcase_23 AC 19 ms
8,388 KB
testcase_24 AC 16 ms
7,776 KB
testcase_25 AC 19 ms
8,192 KB
testcase_26 AC 61 ms
8,620 KB
testcase_27 AC 151 ms
17,616 KB
testcase_28 AC 148 ms
17,444 KB
testcase_29 AC 61 ms
8,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


N = int(input())
S = input()


ans = 0
bb = 0

RLE = RunLengthEncoding(S)

for i, (k, v) in enumerate(RLE):
    if k == "A":
        ans += v - 1
        if v == 1:
            ans += 1
        else:
            ans += i > 0
            ans += i < len(RLE) - 1
    else:
        if v > 1:
            bb = 1

print(ans + bb)
0