結果

問題 No.2021 Not A but B
ユーザー ThetaTheta
提出日時 2022-10-07 18:40:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 8,660 KB
最終ジャッジ日時 2023-09-02 19:13:59
合計ジャッジ時間 3,916 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 16 ms
7,900 KB
testcase_02 AC 16 ms
7,728 KB
testcase_03 AC 15 ms
7,892 KB
testcase_04 AC 17 ms
7,912 KB
testcase_05 AC 16 ms
7,748 KB
testcase_06 AC 16 ms
7,736 KB
testcase_07 AC 15 ms
7,900 KB
testcase_08 AC 85 ms
8,508 KB
testcase_09 AC 83 ms
8,616 KB
testcase_10 AC 84 ms
8,524 KB
testcase_11 AC 81 ms
8,464 KB
testcase_12 AC 81 ms
8,540 KB
testcase_13 AC 81 ms
8,600 KB
testcase_14 AC 82 ms
8,544 KB
testcase_15 AC 82 ms
8,508 KB
testcase_16 AC 82 ms
8,616 KB
testcase_17 AC 80 ms
8,628 KB
testcase_18 AC 85 ms
8,660 KB
testcase_19 AC 86 ms
8,604 KB
testcase_20 AC 85 ms
8,564 KB
testcase_21 AC 19 ms
7,836 KB
testcase_22 AC 18 ms
7,928 KB
testcase_23 AC 18 ms
7,776 KB
testcase_24 AC 16 ms
7,896 KB
testcase_25 AC 17 ms
7,776 KB
testcase_26 AC 16 ms
8,612 KB
testcase_27 AC 101 ms
8,536 KB
testcase_28 AC 100 ms
8,496 KB
testcase_29 AC 139 ms
8,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    length = int(input())
    strings = input()

    if length == 2:
        print(1)
        return

    BB_found = False
    counter = 0
    current_idx = 0
    while current_idx < length-1:
        a_idx = strings.find("A", current_idx)
        if a_idx == 0:
            counter += 1
            current_idx = 1
            continue

        if a_idx == length - 1:
            if strings[a_idx-1] == "B":
                counter += 1
                break

        if a_idx != -1:
            previous_2letters = strings[a_idx-1:a_idx+1]
            if previous_2letters == "AA":
                counter += 1
            else:
                if strings[a_idx+1] == "A":
                    counter += 2
                else:
                    counter += 1

            diff = a_idx - current_idx
            if diff >= 2:
                BB_found = True
            current_idx = a_idx + 1
        else:
            BB_found = True
            break

    if BB_found:
        counter += 1
    print(counter)


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