結果

問題 No.2021 Not A but B
ユーザー sonotarou
提出日時 2022-08-09 23:46:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 551 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 193,052 KB
最終ジャッジ日時 2025-01-30 19:54:03
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n;
string s;

int main () {
    ios::sync_with_stdio(false); 
    cin.tie(0); 

    cin >> n >> s;

    int ans=0, bb=0;
    rep(i,n-1) s.substr(i,2)!="BB" ? ans++ : bb=1;
    rep(i,n-2)if(s.substr(i,3)=="BAB") ans--;
    ans+=bb;    

    cout << ans << '\n';

    return 0;
}
0