제출 #906216

#제출 시각아이디문제언어결과실행 시간메모리
906216LucaIlieChorus (JOI23_chorus)C++17
40 / 100
7094 ms35536 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e3; int a[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; } } for ( int i = 1; i <= n; i++ ) { dp[i][0] = n * n; for ( int l = 1; l <= k; l++ ) { dp[i][l] = n * n; int swapsAdded = 0; for ( int j = i - 1; j >= 0; j-- ) { swapsAdded += max( 0, i - a[j + 1] ); dp[i][l] = min( dp[i][l], dp[j][l - 1] + swapsAdded ); } } } 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...