제출 #906220

#제출 시각아이디문제언어결과실행 시간메모리
906220LucaIlieChorus (JOI23_chorus)C++17
40 / 100
7044 ms96944 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e3; int a[MAX_N + 1], sa[MAX_N + 1], dp[MAX_N + 1][MAX_N + 1]; int main() { int n, k; cin >> n >> k; int countB = 0, countA = 0; for ( int i = 0; i < 2 * n; i++ ) { char ch; cin >> ch; if ( ch == 'A' ) countA++; else { countB++; a[countB] = countA; sa[countB] = sa[countB - 1] + a[countB]; } } for ( int i = 1; i <= n; i++ ) dp[i][0] = n * n; for ( int l = 1; l <= k; l++ ) { for ( int i = 1; i <= n; i++ ) { dp[i][l] = n * n; int p = i; for ( int j = i - 1; j >= 0 && a[j + 1] >= i; j-- ) { dp[i][l] = min( dp[i][l], dp[j][l - 1] ); p = j; } for ( int j = p - 1; j >= 0; j-- ) dp[i][l] = min( dp[i][l], dp[j][l - 1] + i * (p - j) - sa[p] + sa[j] ); } } 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...