結果
問題 | No.2021 Not A but B |
ユーザー |
|
提出日時 | 2022-10-07 18:40:00 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 1,068 bytes |
コンパイル時間 | 138 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-06-12 01:39:09 |
合計ジャッジ時間 | 3,746 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
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()