198262025-12-24 13:29:34ubormaciGyros (30)cpp17Elfogadva 30/302ms504 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
 *
 * notes:
 *
 * int64_t
 * stoi(string s) -> string to int
 * to_string() -> int (or else) to string
 *
 * vector declaration:
 * vector<ll> v(n, 0)
 * vector<vector<ll>> v(n, vector<ll>(n, 0));
 *
 * {if statement} ? {truth value} : {false value}
 *
 * set lower bound/upper bound:
 * 	// . . . m1 . . . d . . . . m2
 *    auto m1_it = b.lower_bound(d);
 *    advance(m1_it, -1);
 *    m1 = *m1_it;
 *	m2 = *b.upper_bound(d);
 *
 * #ifdef LOCAL
 *    freopen("in.txt","r",stdin);
 *    freopen("out.txt","w",stdout);
 * #endif
 *
 * constexpr auto lcm(auto x, auto... xs)
 * {
 *	return ((x = std::lcm(x, xs)), ...);
 * }
 *
 * std::gcd(int a, int b)
 *
 * cout << setprecision(n);
 *
 * set with custom ordering
 * set<ll, decltype(&cmp)> qu(cmp);
 *
 */

typedef int64_t ll;

void put(char which, ll &a, ll &b, ll vc, ll ac, ll bc, ll &vh, ll &ah, ll &bh) {

    if(which == 'a') {

        if(ac * 2 <= a) {
            a -= ac * 2;
            ah = ac;
        }else{
            // we can't fulfill all orders
            ah = a / 2;
            a -= ah * 2;
        }

    }else if(which == 'b') {

        if(bc * 2 <= b) {
            b -= bc * 2;
            bh = bc;
        }else{
            bh = b / 2;
            b -= bh * 2;
        }

    }else if(which == 'v') {

        ll h = min(a, b);

        if(h >= vc) {

            a -= vc;
            b -= vc;
            vh = vc;
        }else{
            a -= h;
            b -= h;
            vh = h;
        }
    }
}

void solve() {

    ll n, a, b;
    cin >> n >> a >> b;

    string s;
    cin >> s;

    ll vc = 0, ac = 0, bc = 0;
    for(const auto & c : s) {
        if(c == 'V') {
            vc++;
        }else if(c == 'C') {
            ac++;
        }else{
            bc++;
        }
    }

    //cerr << "\nn=" << n << "; a=" << a << "; b=" << b;
    //cerr << "\nvc=" << vc << "; ac=" << ac << "; bc=" << bc;

    ll ans = 0;

    vector<char> perm = {'a', 'b', 'v'};
    do{

        ll ares = a;
        ll bres = b;

        ll vh = 0;
        ll ch = 0;
        ll bh = 0;

        for(ll i = 0; i < 3; i++) {
            put(perm[i], ares, bres, vc, ac, bc, vh, ch, bh);
        }

        ans = max(ans, vh + ch + bh);
    }while(std::next_permutation(perm.begin(), perm.end()));

    // permutacios greedy

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

int main()
{
    std::ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);

    ll tests = 0;
    cin >> tests;

    while(tests--)
    {
        solve();
    }

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base30/30
1Elfogadva0/02ms316 KiB
2Elfogadva0/02ms504 KiB
3Elfogadva2/22ms316 KiB
4Elfogadva2/22ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva3/31ms392 KiB
7Elfogadva3/31ms316 KiB
8Elfogadva3/31ms360 KiB
9Elfogadva2/21ms316 KiB
10Elfogadva2/21ms316 KiB
11Elfogadva2/21ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva3/31ms316 KiB
14Elfogadva3/31ms316 KiB