結果

問題 No.2021 Not A but B
ユーザー cankusleepcankusleep
提出日時 2022-07-29 22:07:24
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,562 bytes
コンパイル時間 4,531 ms
コンパイル使用メモリ 132,424 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 21:07:34
合計ジャッジ時間 3,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define LOCAL

using namespace std;

using ll = long long;
// const int mod = 998244353;
// const int mod = 1000000000 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_vector(vector<ll> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        if (i < n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }
    }
}

ll gcd(ll x, ll y) {
    return (y == 0 ? x : gcd(y, x % y));
}
ll lcm(ll x, ll y) {
    return x * y / gcd(x, y);
}

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

vector<int> prime{1};

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    int res = 0;

    int cur = 0;
    char pre = ' ';
    bool start = true;
    bool find = false;
    bool has_b = false;
    for (auto c : s) {
        if (c == 'A') {
            if (pre == 'A') cur++;
            else cur = 1;

            pre = 'A';
        } else {
            if (pre == 'A') {
                if (start) {
                    res += cur;
                } else {
                    if (cur == 1) res++;
                    else res += (cur + 1);
                }
            }
            if (pre == 'B') {
                find = true;
            }
            pre = 'B';
            cur = 0;
            start = false;
            has_b = true;
        }
    }

    if (!has_b) {
        cout << n - 1 << endl;
        return;
    }

    res += cur;

    cout << res + find << endl;
}

int main() {
    quickread();

    int t = 1;
    // bool multi = false;
    // if (multi) cin >> t;
    // else t = 1;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}
0