Submission #72533387


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vmi = vector<mint>;
using vvmi = vector<vmi>;
using vvvmi = vector<vvmi>;
#define all(a) (a).begin(), (a).end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)

ll op(ll a, ll b){
    return a+b;
}
ll e(){return 0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; string s; cin >> n >> s;
    vi a(n+1, 0);
    rep(i, n){
        if(s[i] == 'A'){
            a[i+1] = a[i]+1;
        }else if(s[i] == 'B'){
            a[i+1] = a[i]-1;
        }else{
            a[i+1] = a[i];
        }
    }
    ll ans = 0;
    segtree<ll, op, e> seg(1000010);
    seg.set(500005, 1);
    rep2(i, 1, n+1){
        ll c = 500005+a[i];
        ans += seg.prod(0, c);
        seg.set(c, seg.get(c)+1);
    }cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task E - A > B substring
User applejam
Language C++23 (GCC 15.2.0)
Score 450
Code Size 1242 Byte
Status AC
Exec Time 81 ms
Memory 30232 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 13 ms 27388 KiB
00_sample_01.txt AC 14 ms 27420 KiB
00_sample_02.txt AC 14 ms 27600 KiB
01_random_03.txt AC 80 ms 30140 KiB
01_random_04.txt AC 80 ms 30028 KiB
01_random_05.txt AC 80 ms 30140 KiB
01_random_06.txt AC 80 ms 30036 KiB
01_random_07.txt AC 81 ms 30124 KiB
01_random_08.txt AC 80 ms 30120 KiB
01_random_09.txt AC 80 ms 30228 KiB
01_random_10.txt AC 80 ms 30144 KiB
01_random_11.txt AC 80 ms 30140 KiB
01_random_12.txt AC 80 ms 30164 KiB
01_random_13.txt AC 81 ms 30092 KiB
01_random_14.txt AC 80 ms 30228 KiB
01_random_15.txt AC 80 ms 30024 KiB
01_random_16.txt AC 67 ms 29712 KiB
01_random_17.txt AC 52 ms 28976 KiB
01_random_18.txt AC 43 ms 28756 KiB
01_random_19.txt AC 42 ms 28840 KiB
01_random_20.txt AC 47 ms 28868 KiB
01_random_21.txt AC 56 ms 29068 KiB
01_random_22.txt AC 33 ms 28360 KiB
01_random_23.txt AC 33 ms 28252 KiB
01_random_24.txt AC 80 ms 30140 KiB
01_random_25.txt AC 79 ms 30024 KiB
01_random_26.txt AC 80 ms 30232 KiB
01_random_27.txt AC 80 ms 30080 KiB
01_random_28.txt AC 80 ms 30128 KiB
01_random_29.txt AC 80 ms 30228 KiB
01_random_30.txt AC 79 ms 30228 KiB
01_random_31.txt AC 81 ms 30140 KiB
01_random_32.txt AC 14 ms 27472 KiB
01_random_33.txt AC 14 ms 27452 KiB
01_random_34.txt AC 14 ms 27356 KiB