結果

問題 No.2021 Not A but B
ユーザー eve__fuyuki
提出日時 2024-06-27 16:16:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 198,708 KB
最終ジャッジ日時 2025-02-22 00:47:17
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool non_change = false;
    vector<int> single;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'B' && s[i + 1] == 'B') {
            non_change = true;
        } else if (s[i] == 'B') {
            single.push_back(i + 1);
        } else if (s[i + 1] == 'B') {
            single.push_back(i);
        } else {
            ans++;
        }
    }
    ans += non_change;
    sort(single.begin(), single.end());
    single.erase(unique(single.begin(), single.end()), single.end());
    ans += single.size();
    cout << ans << "\n";
}
0