結果

問題 No.2021 Not A but B
ユーザー みここ
提出日時 2022-12-19 02:56:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 398 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 67,920 KB
最終ジャッジ日時 2025-02-09 16:33:48
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int c = 0, d = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == 'B' && s[i + 1] == 'B')
        {
            c++;
        }
        else if (i > 0 && s[i - 1] == 'B' && s[i + 1] == 'B')
        {
            d++;
        }
    }
    cout << n - 1 - max(0, c - 1) - d << endl;
}
0