제출 #1090868

#제출 시각아이디문제언어결과실행 시간메모리
1090868eltu0815Chorus (JOI23_chorus)C++14
0 / 100
1 ms4444 KiB
#include <bits/stdc++.h> #define MAX 300005 #define MOD (ll)(1048573) #define INF (ll)(1e18) #define inf (int)(1e9) #define eps (double)(1e-8) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int tt, n, m, k, q; string str; int cnt[MAX], pos[MAX]; ll dp[5005][5005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cin >> n >> k >> str; for(int i = 0, tmp = 0, p = 0; i < 2 * n; ++i) { if(str[i] == 'A') cnt[++p] = tmp; else ++tmp; } for(int i = 0, j = 1; i <= n; ++i) { while(j <= n && cnt[j] < i) ++j; pos[i] = j; } for(int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1]; for(int i = 0; i <= n; ++i) for(int j = 0; j <= k; ++j) dp[i][j] = INF; dp[0][0] = 0; for(int i = 1; i <= n; ++i) for(int j = 1; j <= k; ++j) { for(int ii = 0; ii < i; ++ii) { if(pos[ii] <= i) dp[i][j] = min(dp[i][j], dp[ii][j - 1] + cnt[i] - cnt[pos[ii] - 1] - (i - pos[ii] + 1) * ii); else dp[i][j] = min(dp[i][j], dp[ii][j - 1]); } } cout << dp[n][k]; 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...