結果

問題 No.2021 Not A but B
ユーザー masa_wmasa_w
提出日時 2022-07-29 23:02:21
言語 Crystal
(1.11.2)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 253 bytes
コンパイル時間 21,180 ms
コンパイル使用メモリ 253,132 KB
実行使用メモリ 4,964 KB
最終ジャッジ日時 2023-09-26 22:37:17
合計ジャッジ時間 22,797 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 3 ms
4,500 KB
testcase_02 AC 2 ms
4,464 KB
testcase_03 AC 3 ms
4,408 KB
testcase_04 AC 2 ms
4,528 KB
testcase_05 AC 2 ms
4,504 KB
testcase_06 AC 3 ms
4,408 KB
testcase_07 AC 3 ms
4,548 KB
testcase_08 AC 6 ms
4,864 KB
testcase_09 AC 6 ms
4,844 KB
testcase_10 AC 7 ms
4,964 KB
testcase_11 AC 6 ms
4,768 KB
testcase_12 AC 6 ms
4,880 KB
testcase_13 AC 6 ms
4,912 KB
testcase_14 AC 6 ms
4,824 KB
testcase_15 AC 6 ms
4,944 KB
testcase_16 AC 7 ms
4,792 KB
testcase_17 AC 6 ms
4,868 KB
testcase_18 AC 6 ms
4,824 KB
testcase_19 AC 6 ms
4,868 KB
testcase_20 AC 6 ms
4,860 KB
testcase_21 AC 3 ms
4,424 KB
testcase_22 AC 2 ms
4,504 KB
testcase_23 AC 3 ms
4,564 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,428 KB
testcase_26 AC 5 ms
4,880 KB
testcase_27 AC 6 ms
4,852 KB
testcase_28 AC 5 ms
4,772 KB
testcase_29 AC 5 ms
4,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
s = read_line
cnt = 0
cnt_bb = 0
(n-1).times do |i|
    cnt += 1  if i < n-2 && s[i] == 'B' && s[i+1] == 'A' && s[i+2] == 'B'
    cnt_bb += 1 if s[i] == 'B' && s[i+1] == 'B'
end
ans = n- 1 -cnt
ans -= cnt_bb - 1 if cnt_bb > 0
puts ans
0