結果

問題 No.2021 Not A but B
ユーザー V_Melville
提出日時 2022-07-30 17:39:19
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 4,711 ms
コンパイル使用メモリ 314,356 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 14:03:29
合計ジャッジ時間 5,780 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    int ans = 0;
    rep(i, n) {
        bool ok = false;
        if (s[i] == 'A') {
            if (i > 0 and s[i-1] == 'B') ok = true;
            if (i < n-1 and s[i+1] == 'B') ok = true;
        }
        if (ok) ans++;
    }
    
    rep(i, n-1) {
        ans += s[i] == 'A' and s[i+1] == 'A';
    }
    bool ok = false;
    rep(i, n-1) {
        if (s[i] == 'B' and s[i+1] == 'B') ok = true;
    }
    
    if (ok) ans++;
    cout << ans << '\n';
    
    return 0;
}
0