提出 #70627638


ソースコード 拡げる

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <tuple>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using ll = long long;
using ld = long double;
using namespace std;
#define endl "\n";
#define ff first
#define ss second

#define forn(i,n) for(int i=0;i<n;i++)
#define dbgv(v) cout<<#v<<" "<<v<<endl
#define dbga(a,n) forn(i,n-1) {cout<<a[i]<<' ';} cout<<a[n-1]<<'\n';
#define all(v) (v).begin(), (v).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, A, B;
    if (!(cin >> N >> A >> B)) return 0;
    string S;
    cin >> S;

    
    vector<int> pa(N+1, 0), pb(N+1, 0);
    for (int i = 0; i < N; ++i) {
        pa[i+1] = pa[i] + (S[i] == 'a');
        pb[i+1] = pb[i] + (S[i] == 'b');
    }

    ll ans = 0;
    for (int l = 1; l <= N; ++l) {
        
        int needA = pa[l-1] + A;
        auto itA = lower_bound(pa.begin() + l, pa.end(), needA);
        if (itA == pa.end()) continue;
        int f = int(itA - pa.begin()); 

        
        int maxB = pb[l-1] + (B - 1);
        
        auto itB = upper_bound(pb.begin() + l, pb.end(), maxB);
        int g = int(itB - pb.begin()) - 1; 

        if (g >= f) ans += (g - f + 1);
    }

    cout << ans << "\n";
    return 0;
}

提出情報

提出日時
問題 C - Truck Driver
ユーザ SummitDevil
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1909 Byte
結果 AC
実行時間 18 ms
メモリ 6196 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 25
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
hand.txt AC 1 ms 3592 KiB
random_01.txt AC 18 ms 6020 KiB
random_02.txt AC 16 ms 6068 KiB
random_03.txt AC 17 ms 6092 KiB
random_04.txt AC 17 ms 6092 KiB
random_05.txt AC 15 ms 6096 KiB
random_06.txt AC 15 ms 6092 KiB
random_07.txt AC 14 ms 6196 KiB
random_08.txt AC 12 ms 6092 KiB
random_09.txt AC 15 ms 6152 KiB
random_10.txt AC 17 ms 6180 KiB
random_11.txt AC 17 ms 6132 KiB
random_12.txt AC 15 ms 6148 KiB
random_13.txt AC 11 ms 6096 KiB
random_14.txt AC 13 ms 6152 KiB
random_15.txt AC 11 ms 6156 KiB
random_16.txt AC 10 ms 6156 KiB
random_17.txt AC 9 ms 6148 KiB
random_18.txt AC 9 ms 6020 KiB
random_19.txt AC 6 ms 6080 KiB
random_20.txt AC 6 ms 6152 KiB
random_21.txt AC 9 ms 6128 KiB
random_22.txt AC 6 ms 6100 KiB
sample_01.txt AC 1 ms 3592 KiB
sample_02.txt AC 1 ms 3592 KiB