提出 #70613489


ソースコード 拡げる

#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
using ll = long long;
using db = double;
const ll N = 1e6 + 5;
const ll md = 998244353;
const ll MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db eps = 1e-6;
const db E = 2.718281828459045;
typedef pair<ll, ll> PLL;
#define fi first
#define se second
void solve()
{
    ll n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    s = '#' + s;
    vector<ll> pre(n + 1);
    vector<ll> pre2(n + 1);
    for (ll i = 1; i <= n;i++)
    {
        pre[i] = pre[i - 1];
        pre2[i] = pre2[i - 1];
        if(s[i]=='a')
            pre[i]++;
        else
            pre2[i]++;
    }
    ll ans = 0;
    for (ll i = 1; i <= n;i++)
    {
        auto it1 = lower_bound(pre.begin() + i , pre.end(), a + pre[i-1]);
        auto it2 = lower_bound(pre2.begin() + i , pre2.end(), b+pre2[i-1]);

        if(it1!=pre.end())
        {
            ll k1 =  it1-pre.begin();
            ll k2 = it2-pre2.begin();
            // cout << it1 - pre.begin() << ' ' << it2 - pre2.begin() << '\n';
            if(k2>k1)
                ans += k2 - k1;
        }
    }
    cout << ans << '\n';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T;
    T = 1;
    //cin>>T;
    while (T--)
    {
        solve();
    }
}

提出情報

提出日時
問題 C - Truck Driver
ユーザ AChievedreaM
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1438 Byte
結果 AC
実行時間 27 ms
メモリ 8492 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 3616 KiB
random_01.txt AC 27 ms 8428 KiB
random_02.txt AC 25 ms 8412 KiB
random_03.txt AC 24 ms 8468 KiB
random_04.txt AC 23 ms 8308 KiB
random_05.txt AC 18 ms 8492 KiB
random_06.txt AC 19 ms 8408 KiB
random_07.txt AC 18 ms 8412 KiB
random_08.txt AC 15 ms 8436 KiB
random_09.txt AC 21 ms 8408 KiB
random_10.txt AC 23 ms 8292 KiB
random_11.txt AC 22 ms 8472 KiB
random_12.txt AC 21 ms 8320 KiB
random_13.txt AC 14 ms 8288 KiB
random_14.txt AC 17 ms 8320 KiB
random_15.txt AC 14 ms 8316 KiB
random_16.txt AC 13 ms 8388 KiB
random_17.txt AC 12 ms 8440 KiB
random_18.txt AC 12 ms 8484 KiB
random_19.txt AC 12 ms 8432 KiB
random_20.txt AC 11 ms 8488 KiB
random_21.txt AC 12 ms 8316 KiB
random_22.txt AC 11 ms 8316 KiB
sample_01.txt AC 1 ms 3476 KiB
sample_02.txt AC 1 ms 3572 KiB