1932021-02-05 20:25:30kidesoGyros (30)cpp11Wrong answer 15/302ms2260 KiB
#include <iostream>
#include <vector>
#include <string>

using namespace std;

//ifstream cin("gyros.in");
//ofstream cout("gyros.out");

struct adat
{
    int max_r, C, B;
};

int T, N, B, C;
string s;

int megold(string s)
{
    int v = -1, c = -1, b = -1;
    vector <adat> x(N + 1, { 0,0,0 });
    
    x[0] = { 0,C,B };
    if (C >= 2) c = 0;
    if (B >= 2) b = 0;

    if (C >= 1 && B >= 1) v = 0;

    for (int i = 1; i <= N; ++i)
    {
        x[i] = x[i - 1];

        if (s[i - 1] == 'B')
        {
            if (b != -1 && x[b].max_r + 1 > x[i].max_r) x[i] = { x[b].max_r + 1,x[b].C,x[b].B - 2 };
            else if (b != -1 && x[b].max_r + 1 == x[i].max_r)
            {
                if (x[b].B - 2 > x[i].B) x[i] = { x[i].max_r,x[b].C,x[b].B - 2 };
            }

        }
        else if (s[i - 1] == 'C')
        {
            if (c != -1 && x[c].max_r + 1 > x[i].max_r) x[i] = { x[c].max_r + 1,x[c].C - 2,x[c].B };
            else if (c != -1 && x[c].max_r + 1 == x[i].max_r)
            {
                if (x[c].C - 2 > x[i].C) x[i] = { x[i].max_r,x[c].C - 2,x[c].B };
            }
        }
        else
        {
            if (v != -1 && x[v].max_r + 1 > x[i].max_r) x[i] = { x[v].max_r + 1,x[v].C - 1,x[v].B - 1 };
            else if (v != -1 && x[v].max_r + 1 == x[i].max_r)
            {
                if (x[v].C - 1 > x[i].C || x[v].B - 1 > x[v].B) x[i] = { x[i].max_r,x[c].C - 1,x[c].B - 1 };
            }
        }


        if (x[i].B >= 1 && x[i].C >= 1) v = i;
        if (x[i].B >= 2) b = i;
        if (x[i].C >= 2) c = i;
    }

    return x[N].max_r;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> T;

    while (T)
    {
        cin >> N >> C >> B;
        cin >> s;
        cout << megold(s) << '\n';

        --T;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base15/30
1Accepted0/02ms1768 KiB
2Accepted0/02ms2108 KiB
3Accepted2/22ms1884 KiB
4Accepted2/21ms1944 KiB
5Accepted2/21ms1884 KiB
6Wrong answer0/31ms1900 KiB
7Wrong answer0/31ms2152 KiB
8Wrong answer0/31ms1916 KiB
9Accepted2/21ms1908 KiB
10Accepted2/21ms1908 KiB
11Accepted2/21ms1916 KiB
12Accepted3/31ms1968 KiB
13Wrong answer0/31ms2244 KiB
14Wrong answer0/32ms2260 KiB