Submission #70667865


Source Code Expand

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    vector<int> cntA(n+1, 0), cntB(n+1, 0);
    for(int i = 0; i < n; i++){
        cntA[i+1] = cntA[i];
        cntB[i+1] = cntB[i];

        if(s[i] == 'a') cntA[i+1]++;
        else            cntB[i+1]++;
    }

    // for(int i = 0; i < n+1; i++) cout << cntA[i] << " ";
    // cout << endl;
    // for(int i = 0; i < n+1; i++) cout << cntB[i] << " ";
    // cout << endl;

    ll ans = 0;
    for(int i = 0; i < n; i++){
        int idx1 = distance(cntA.begin(), lower_bound(cntA.begin(), cntA.end(), a + cntA[i]));
        int idx2 = distance(cntB.begin(), lower_bound(cntB.begin(), cntB.end(), b + cntB[i]));
        // cout << idx1 << " " << idx2 << endl;
        ans += max(0, idx2 - idx1);
    }

    cout << ans << endl;
}

Submission Info

Submission Time
Task C - Truck Driver
User sakimori_coder
Language C++23 (GCC 15.2.0)
Score 300
Code Size 915 Byte
Status AC
Exec Time 28 ms
Memory 6164 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 25
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand.txt AC 1 ms 3540 KiB
random_01.txt AC 20 ms 6152 KiB
random_02.txt AC 19 ms 6060 KiB
random_03.txt AC 20 ms 6072 KiB
random_04.txt AC 20 ms 6064 KiB
random_05.txt AC 23 ms 6160 KiB
random_06.txt AC 23 ms 6132 KiB
random_07.txt AC 23 ms 6104 KiB
random_08.txt AC 23 ms 6056 KiB
random_09.txt AC 22 ms 6036 KiB
random_10.txt AC 23 ms 6092 KiB
random_11.txt AC 24 ms 6164 KiB
random_12.txt AC 22 ms 6100 KiB
random_13.txt AC 24 ms 6132 KiB
random_14.txt AC 27 ms 6128 KiB
random_15.txt AC 24 ms 6036 KiB
random_16.txt AC 24 ms 6036 KiB
random_17.txt AC 27 ms 6156 KiB
random_18.txt AC 28 ms 6072 KiB
random_19.txt AC 14 ms 6156 KiB
random_20.txt AC 23 ms 6136 KiB
random_21.txt AC 22 ms 6060 KiB
random_22.txt AC 22 ms 6068 KiB
sample_01.txt AC 1 ms 3592 KiB
sample_02.txt AC 1 ms 3564 KiB