結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <numeric>
using namespace std;

static inline void solution() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  bool f = false;
  for (int i = 0; i < n - 1; i++) {
    if (s.substr(i, 2) != "BB") {
      ans += 1;
    } else {
      f = true;
    }
  }
  for (int i = 0; i < n - 2; i++) {
    if (s.substr(i, 3) == "BAB") {
      ans -= 1;
    }
  }
  if (f) {
    ans += 1;
  }

  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  solution();
  return 0;
}
0