提出 #70665088


ソースコード 拡げる

// PriashisG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

    // Typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,
tree_order_statistics_node_update> ordered_multiset;
/*
    greater<int> for large to small
    less_equal for not unique
    finding sz-th element --> os.find_by_order(sz);                           // O(log n)
    finding the number of elements smaller than x --> os.order_by_szey(x);   // O(log n)
    os.erase(x);
*/

    // Macros
#define PB push_back
#define IN insert
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
#define GCD __gcd
#define F first
#define S second
#define endl '\n'
#define LB lower_bound
#define UB upper_bound
#define DEBUG(i) cout << "DEBUG " << i << "\n";
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define GT(x) greater<x>()
#define setpre(n) fixed << setprecision(n)
#define SZ(x) x.size()
#define on_bit(x) __builtin_popcount(x)

    // Functions
template <typename T> void pv(vector<T> &a){
    for (T u : a) cout << u << ' ';
    cout << '\n';
}

template <typename T> void pv2(vector<vector<T>> &a){
    trav(aa, a) pv(aa);
}

template <typename T, typename U> void pvp( vector<pair<T, U>> &a){
    trav(p, a) cout << "(" << p.F << ", " << p.S << ") ";
    cout << '\n';
}

    // Constants
const ll MOD7 = 1e9 + 7;
const ll MOD9 = 998244353;
const ll INF = LLONG_MAX;

    // Custom Functions
void fast(){
    ios::sync_with_stdio(false); cin.tie(0);
}

ll LCM(ll a, ll b){
   return (a * b) / GCD(a, b);
}

    // Custom Comparator
bool cmp(const pair<ll, ll>& x, const pair<ll, ll>& y){
    if (x.F == y.F) return x.S > y.S;
    else return x.F < y.F;
}

    // Global Variables

void solve(ll tc){

    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    vll na(n + 2, 0ll), nb(n + 2, 0ll);
    for (int i = 1; i <= n; i++){
        if (s[i - 1] == 'a') na[i]++;
        else nb[i]++;
        na[i] += na[i - 1];
        nb[i] += nb[i - 1];
    }

    ll ans = 0;
    int l1 = 1, l2 = 1;
    for (int r = 1; r <= n; r++) {
        while (l1 <= r && nb[r] - nb[l1 - 1] >= b) l1++;
        while (l2 <= r && na[r] - na[l2 - 1] >= a) l2++;
        if (l2 - 1 >= l1) ans += l2 - l1;
    }


    cout << ans << '\n';
    
}




int main(void){

    fast(); 
    // precal();

    // freopen("final_product_chapter_1_validation_input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ll t = 1;
    int i = 1;
    // cin >> t;
    // for (ll i = 1; i <= t; i++) 
        solve(i);

}






提出情報

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

コンパイルエラー

./Main.cpp: In function 'void solve(ll)':
./Main.cpp:82:15: warning: unused parameter 'tc' [-Wunused-parameter]
   82 | void solve(ll tc){
      |            ~~~^~
./Main.cpp: In function 'int main()':
./Main.cpp:121:8: warning: unused variable 't' [-Wunused-variable]
  121 |     ll t = 1;
      |        ^

ジャッジ結果

セット名 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 3624 KiB
random_01.txt AC 5 ms 8524 KiB
random_02.txt AC 4 ms 8524 KiB
random_03.txt AC 4 ms 8524 KiB
random_04.txt AC 4 ms 8428 KiB
random_05.txt AC 4 ms 8376 KiB
random_06.txt AC 5 ms 8452 KiB
random_07.txt AC 5 ms 8484 KiB
random_08.txt AC 5 ms 8332 KiB
random_09.txt AC 6 ms 8404 KiB
random_10.txt AC 5 ms 8396 KiB
random_11.txt AC 6 ms 8444 KiB
random_12.txt AC 6 ms 8496 KiB
random_13.txt AC 6 ms 8496 KiB
random_14.txt AC 6 ms 8456 KiB
random_15.txt AC 6 ms 8496 KiB
random_16.txt AC 5 ms 8364 KiB
random_17.txt AC 5 ms 8452 KiB
random_18.txt AC 5 ms 8476 KiB
random_19.txt AC 4 ms 8348 KiB
random_20.txt AC 5 ms 8452 KiB
random_21.txt AC 4 ms 8324 KiB
random_22.txt AC 4 ms 8456 KiB
sample_01.txt AC 1 ms 3596 KiB
sample_02.txt AC 1 ms 3600 KiB