이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define dforn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
const int MAXN=5010, INF=1e7;
int n, K, pos[MAXN], cost[MAXN][MAXN], dp[MAXN][MAXN];
char str[MAXN];
vector<bool> imp;
int main(){
scanf("%d %d", &n, &K);
scanf("%s", str);
forn(i, n){
int cnA=0, cnB=0, cn=0;
forn(j, 2*n){
if(str[j]=='A'){
cnA++;
if(cnA>i) imp.PB(0);
}
else{
cnB++;
if(cnB>i) imp.PB(1);
}
}
forn(j, 2*(n-i)) if(!imp[j]) pos[cn++]=j;
forsn(j, 1, cn+1) forn(k, j) cost[i][j]+=pos[k]-k;
imp.clear();
}
forn(i, n) dp[0][i]=INF;
forsn(i, 1, K+1) dp[i][n]=INF;
forsn(i, 1, K+1) dforn(j, n){
dp[i][j]=INF;
forsn(k, 1, n-j+1) dp[i][j]=min(dp[i][j], dp[i-1][j+k] + cost[j][k]);
}
printf("%d\n", dp[K][0]);
}
컴파일 시 표준 에러 (stderr) 메시지
chorus.cpp: In function 'int main()':
chorus.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d %d", &n, &K);
| ~~~~~^~~~~~~~~~~~~~~~~
chorus.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%s", str);
| ~~~~~^~~~~~~~~~~
# | 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... |