답안 #741746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741746 2023-05-14T18:33:43 Z Username4132 Chorus (JOI23_chorus) C++14
40 / 100
7000 ms 81396 KB
#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) cost[i][j]=cost[i][j-1]+pos[j-1]-j+1;
        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]);
}

Compilation message

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);
      |     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 22 ms 3332 KB Output is correct
19 Correct 51 ms 4428 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 4 ms 2772 KB Output is correct
22 Correct 76 ms 5804 KB Output is correct
23 Correct 76 ms 5708 KB Output is correct
24 Correct 5 ms 2772 KB Output is correct
25 Correct 74 ms 5740 KB Output is correct
26 Correct 69 ms 5236 KB Output is correct
27 Correct 27 ms 3764 KB Output is correct
28 Correct 27 ms 3700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 22 ms 3332 KB Output is correct
19 Correct 51 ms 4428 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 4 ms 2772 KB Output is correct
22 Correct 76 ms 5804 KB Output is correct
23 Correct 76 ms 5708 KB Output is correct
24 Correct 5 ms 2772 KB Output is correct
25 Correct 74 ms 5740 KB Output is correct
26 Correct 69 ms 5236 KB Output is correct
27 Correct 27 ms 3764 KB Output is correct
28 Correct 27 ms 3700 KB Output is correct
29 Execution timed out 7048 ms 81396 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 22 ms 3332 KB Output is correct
19 Correct 51 ms 4428 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 4 ms 2772 KB Output is correct
22 Correct 76 ms 5804 KB Output is correct
23 Correct 76 ms 5708 KB Output is correct
24 Correct 5 ms 2772 KB Output is correct
25 Correct 74 ms 5740 KB Output is correct
26 Correct 69 ms 5236 KB Output is correct
27 Correct 27 ms 3764 KB Output is correct
28 Correct 27 ms 3700 KB Output is correct
29 Execution timed out 7048 ms 81396 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 22 ms 3332 KB Output is correct
19 Correct 51 ms 4428 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 4 ms 2772 KB Output is correct
22 Correct 76 ms 5804 KB Output is correct
23 Correct 76 ms 5708 KB Output is correct
24 Correct 5 ms 2772 KB Output is correct
25 Correct 74 ms 5740 KB Output is correct
26 Correct 69 ms 5236 KB Output is correct
27 Correct 27 ms 3764 KB Output is correct
28 Correct 27 ms 3700 KB Output is correct
29 Execution timed out 7048 ms 81396 KB Time limit exceeded
30 Halted 0 ms 0 KB -