結果
| 問題 |
No.2021 Not A but B
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-29 21:42:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 1,006 bytes |
| コンパイル時間 | 2,212 ms |
| コンパイル使用メモリ | 192,348 KB |
| 最終ジャッジ日時 | 2025-01-30 15:08:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
// debug
#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
// #include "atcoder/all"
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
int N;
string S;
cin >> N >> S;
bool no_change = false;
int ans = 0;
for (int i = 0; i < N - 1; i++) {
if (S[i] == 'B' && S[i + 1] == 'B') {
if (!no_change) {
ans++;
no_change = true;
}
continue;
}
if (S[i + 1] == 'A') {
ans++;
continue;
}
if (i == 0) {
ans++;
continue;
}
if (S[i - 1] == 'A') ans++;
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}