이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<pii>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t)){
cerr<<", ";
}
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main(){
int n, k;
string s;
cin>>n>>k>>s;
vi V(n+1);
int a=0, b=1;
for(char c:s){
if(c=='A')a++;
else{
V[b]=a;
b++;
}
}
vector<vector<ll> > dp(n+1, vector<ll>(k+1, 1e18));
dp[0][0]=0;
for(int kk=1; kk<=k; kk++){
for(int i=kk; i<=n; i++){
for(int j=0; j<i; j++){
ll c=0;
for(int l=j+1; l<=i; l++){
c+=max(0, i-V[l]);
}
dp[i][kk]=min(dp[i][kk], dp[j][kk-1]+c);
}
}
}
cout<<dp[n][k];
}
# | 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... |