#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')
a[++bra] = brb;
else
brb++;
for(int i = 0; i <= 2 * n; i++)
for(int j = 0; j <= k; 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++)
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |