Submission #72549334


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fix(x) fixed << setprecision(x)
#define rep(i, start, end) for (auto i = (start); (i) < (end); (i)++)
#define repe(i, start, end) for (auto i = (start); (i) <= (end); (i)++)
#define rrep(i, start, end) for (auto i = (start); (i) >= (end); (i)--)

constexpr auto PI = 3.14159265358979;
constexpr int INF = 1e+9;
constexpr long long INFL = 1e+18;

using ll = long long;
using lld = long double;
// using mint = modint1000000007;
using mint = modint998244353;
using Pair_int = pair<int, int>;
using Pair_ll = pair<ll, ll>;
template <class T>
using Graph = vector<vector<T>>;

template <class T1, class T2>
inline auto div_floor(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a >= 0)
        return a / b;
    else
        return (a + 1) / b - 1;
}
template <class T1, class T2>
inline auto div_ceil(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a <= 0)
        return a / b;
    else
        return (a - 1) / b + 1;
}
ll floor_sqrt(ll x)
{
    ll y = sqrt(x);
    while (y * y > x)
        y--;
    while ((y + 1) * (y + 1) <= x)
        y++;
    return y;
}
ll pow_int(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}
ll pow_mod(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll gcd(ll x, ll y)
{
    if (x < y)
        swap(x, y);
    ll r;
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
ll lcm(ll x, ll y) { return ll(x / gcd(x, y)) * y; }
ll nCk(ll n, ll r)
{
    if (r < 0 || n < r)
        return 0;
    ll ans = 1;
    for (ll i = 1; i <= r; i++)
    {
        ans *= n--;
        ans /= i;
    }
    return ans;
}
int get_rand(int seed, int min, int max)
{
    static mt19937_64 mt64(seed);
    uniform_int_distribution<int> get_rand_int(min, max);
    return get_rand_int(mt64);
}
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T1, class T2>
inline auto mod(T1 x, T2 r) { return (x % r + r) % r; }

// ======================================== //

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    fenwick_tree<int> fw(2 * N + 1);
    fw.add(0 + N, 1);

    ll ps = 0, ans = 0;
    rep(i, 0, N)
    {
        if (S[i] == 'A')
            ps++;
        else if (S[i] == 'B')
            ps--;

        fw.add(ps + N, 1);
        ans += fw.sum(0, ps + N);
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task E - A > B substring
User Yuulis
Language C++23 (GCC 15.2.0)
Score 450
Code Size 2935 Byte
Status AC
Exec Time 17 ms
Memory 7996 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 35
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3532 KiB
00_sample_01.txt AC 1 ms 3412 KiB
00_sample_02.txt AC 1 ms 3572 KiB
01_random_03.txt AC 17 ms 7732 KiB
01_random_04.txt AC 16 ms 7868 KiB
01_random_05.txt AC 17 ms 7724 KiB
01_random_06.txt AC 16 ms 7848 KiB
01_random_07.txt AC 17 ms 7852 KiB
01_random_08.txt AC 17 ms 7988 KiB
01_random_09.txt AC 16 ms 7848 KiB
01_random_10.txt AC 16 ms 7868 KiB
01_random_11.txt AC 17 ms 7856 KiB
01_random_12.txt AC 17 ms 7900 KiB
01_random_13.txt AC 17 ms 7756 KiB
01_random_14.txt AC 16 ms 7820 KiB
01_random_15.txt AC 16 ms 7776 KiB
01_random_16.txt AC 13 ms 6972 KiB
01_random_17.txt AC 10 ms 5944 KiB
01_random_18.txt AC 7 ms 5356 KiB
01_random_19.txt AC 8 ms 5496 KiB
01_random_20.txt AC 8 ms 5608 KiB
01_random_21.txt AC 11 ms 6184 KiB
01_random_22.txt AC 6 ms 4708 KiB
01_random_23.txt AC 6 ms 4708 KiB
01_random_24.txt AC 14 ms 7828 KiB
01_random_25.txt AC 13 ms 7996 KiB
01_random_26.txt AC 15 ms 7844 KiB
01_random_27.txt AC 14 ms 7772 KiB
01_random_28.txt AC 15 ms 7732 KiB
01_random_29.txt AC 13 ms 7832 KiB
01_random_30.txt AC 14 ms 7852 KiB
01_random_31.txt AC 13 ms 7792 KiB
01_random_32.txt AC 1 ms 3612 KiB
01_random_33.txt AC 1 ms 3388 KiB
01_random_34.txt AC 1 ms 3664 KiB