結果
| 問題 |
No.2021 Not A but B
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-09 02:20:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 675 bytes |
| コンパイル時間 | 1,585 ms |
| コンパイル使用メモリ | 167,092 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-24 23:40:36 |
| 合計ジャッジ時間 | 2,875 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) begin(a), end(a)
#define sz(x) (int)((x).size())
#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) 42
#endif
void solve() {
int n; cin >> n;
string s; cin >> s;
int ans = 0;
bool BB = false;
for (int i = 1; i < n; i++) {
ans += s[i] == 'A' || s[i - 1] == 'A';
BB |= s[i] == 'B' && s[i - 1] == 'B';
}
for (int i = 1; i + 1 < n; i++) {
ans -= s[i - 1] == 'B' && s[i] == 'A' && s[i + 1] == 'B';
}
cout << (ans + BB) << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}