結果
問題 | No.2021 Not A but B |
ユーザー |
![]() |
提出日時 | 2024-06-27 16:16:04 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 773 bytes |
コンパイル時間 | 2,208 ms |
コンパイル使用メモリ | 206,552 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 16:16:08 |
合計ジャッジ時間 | 3,543 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#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";}