This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int dp[501][501];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,x,br = 0;
cin >> n >> x;
string s;
cin >> s;
vector<int> bruh(0);
for(int i = 0; i < 2*n; i++) {
if(s[i] == 'A') {
br++;
}
else {
bruh.push_back(br);
}
}
for(int i = 0; i <= n; i++) {
dp[0][i] = 0;
}
for(int i = 1; i <= n; i++) {
for(int k = 0; k <= n; k++) {
dp[i][k] = 1e9;
}
int sb = 0;
for(int j = i-1; j >= 0; j--) {
sb+=max(0,i-bruh[j]);
for(int k = 0; k < n; k++) {
dp[i][k+1] = min(dp[i][k+1],dp[j][k]+sb);
}
}
}
cout << dp[n][x];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |