이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
int lft[1000005];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
string s;
cin >> n >> k >> s;
if (n > 500) return 0;
int cntA = 0, cntB = 0;
for (int i = 0; i < n + n; ++i) {
if (s[i] == 'B') ++cntB;
else lft[++cntA] = cntB;
}
const ll INF = 1e18;
vector<vector<ll>> dp(k + 1, vector<ll>(n + 1, INF));
ll fin = INF;
dp[0][0] = 0;
for (int i = 0; i < k; ++i) {
for (int j = 1; j <= n; ++j) {
ll sum = 0;
for (int p = j; p <= n; ++p) {
sum += max(0, lft[p] - (j - 1));
dp[i + 1][p] = min(dp[i + 1][p], dp[i][j - 1] + sum);
}
}
fin = min(fin, dp[i + 1][n]);
}
cout << fin << "\n";
}
# | 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... |