結果
問題 | No.2021 Not A but B |
ユーザー |
|
提出日時 | 2022-07-30 00:47:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 1,905 bytes |
コンパイル時間 | 2,106 ms |
コンパイル使用メモリ | 198,316 KB |
最終ジャッジ日時 | 2025-01-30 16:25:45 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/all>using namespace std;//using namespace atcoder;using ll = long long;using vll = vector<ll>;using vvll = vector<vll>;using vvvll = vector<vvll>;using vvvvll = vector<vvvll>;using vb = vector<bool>;using vvb = vector<vb>;using vvvb = vector<vvb>;using vvvvb = vector<vvvb>;using vd = vector<double>;using vvd = vector<vd>;using vvvd = vector<vvd>;#define all(A) A.begin(),A.end()#define ALL(A) A.begin(),A.end()#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;template<class T>bool chmax(T& p, T q, bool C = 1) {if (C == 0 && p == q) {return 1;}if (p < q) {p = q;return 1;}else {return 0;}}template<class T>bool chmin(T& p, T q, bool C = 1) {if (C == 0 && p == q) {return 1;}if (p > q) {p = q;return 1;}else {return 0;}}ll gcd(ll(a), ll(b)) {if (b == 0)return a;ll c = a;while (a % b != 0) {c = a % b;a = b;b = c;}return b;}vector<vector<pair<ll,pair<ll,ll>>>> G;vll D;vector<bool> seen;void dfs(ll n){seen[n]=1;for(auto v:G[n]){if(seen[v.first])continue;if(v.second.second==1){D[v.second.first]=1;}else D[v.second.first]=0;dfs(v.first);}return;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);ll N;cin>>N;string S;cin>>S;ll an=0;ll b=0;rep(i,N-1){if(S[i]=='A'&&S[i+1]=='A'){an++;}else if(S[i]=='A'&&S[i+1]=='B')an++;else if(S[i]=='B'&&S[i+1]=='A'){if(i!=N-1&&S[i+2]!='B')an++;}else b++;}cout<<(an)+(b>0)<<endl;}