結果

問題 No.2021 Not A but B
ユーザー rogi52
提出日時 2022-09-27 15:32:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 194,592 KB
最終ジャッジ日時 2025-02-07 17:19:51
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; string S; cin >> N >> S;
    int BB = 0, AA = 0, A = 0;
    rep(i,N-1) {
        if(S.substr(i, 2) == "BB") BB = 1;
        if(S.substr(i, 2) == "AA") AA++;
    }

    rep(i,N) if(S[i] == 'A') {
        int ok = 0;
        ok |= 0 <= i - 1 && S[i - 1] == 'B';
        ok |= i + 1 < N  && S[i + 1] == 'B';
        A += ok;
    }
    cout << BB + AA + A << endl;
}
0