Submission #938140

#TimeUsernameProblemLanguageResultExecution timeMemory
938140Ice_manChorus (JOI23_chorus)C++14
40 / 100
6414 ms32348 KiB
#include <iostream>
#include <chrono>

#define maxn 2005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")

using namespace std;

std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}


int n , k;
string s;

void read()
{
    cin >> n >> k;
    cin >> s;
}

int dp[maxn][maxn] , a[maxn];
int bra , brb;

int calc(int y , int x)
{
    int ret = 0;

    for(int i = y + 1; i <= x; i++)
        if(a[i] >= y)
            ret += a[i] - y;

    return ret;
}


void calc_dp()
{
    bra = 0;
    brb = 0;

    for(char c : s)
        if(c == 'A')
        {
            bra++;
            a[bra] = brb;
        }
        else
            brb++;

    /**for(int i = 0; i < 2 * n; i++)
        cout << a[i] << " ";
    cout << endl;

    cout << bra << " " << brb << endl;*/

    for(int i = 0; i <= k; i++)
        for(int j = 0; j <= n; j++)
            dp[i][j] = INF;

    dp[0][0] = 0;

    for(int i = 1; i <= k; i++)
        for(int j = 1; j <= n; j++)
            for(int _k = 0; _k < j; _k++)
            {
                ///cout << calc(_k , j) << endl;
                dp[i][j] = min(dp[i][j] , dp[i - 1][_k] + calc(_k , j));
            }


    cout << dp[k][n] << endl;
}




int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    startT = std::chrono::high_resolution_clock::now();

    read();
    calc_dp();


    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...