답안 #789130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789130 2023-07-21T05:56:04 Z 반딧불(#10041) Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 19540 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void input();
void solve();

int main(){
    input();
    solve();
}

int n, k;
int arr[2000002]; /// A = ( = 1, B = ) = -1
char str[2000002];

int a[1000002], b[1000002], bta[1000002];

void input(){
    scanf("%d %d", &n, &k);
    scanf("%s", str+1);
    int aCnt = 0, bCnt = 0;
    for(int i=1; i<=n+n; i++){
        if(str[i] == 'A') arr[i] = 1, a[++aCnt] = i;
        else arr[i] = -1, b[++bCnt] = i, bta[bCnt] = aCnt;
    }
}

ll DP[502][502];

ll cost(int s, int e){
    ll ret = 0;
    for(int i=s; i<=e; i++) ret += max(e - bta[i], 0);
    return ret;
}

void solve(){
    for(int i=0; i<=n; i++) for(int j=0; j<=k; j++) DP[i][j] = 1e18;

    DP[0][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<k; j++){
            if(DP[i-1][j] == 1e18) continue;
            for(int x=i; x<=n; x++){
                DP[x][j+1] = min(DP[x][j+1], DP[i-1][j] + cost(i, x));
            }
        }
    }

    printf("%lld", DP[n][k]);
}

Compilation message

chorus.cpp: In function 'void input()':
chorus.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
chorus.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%s", str+1);
      |     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 26 ms 1028 KB Output is correct
18 Correct 993 ms 2304 KB Output is correct
19 Correct 1876 ms 2308 KB Output is correct
20 Correct 1 ms 2232 KB Output is correct
21 Correct 27 ms 2260 KB Output is correct
22 Correct 1921 ms 2308 KB Output is correct
23 Correct 1834 ms 2308 KB Output is correct
24 Correct 129 ms 2304 KB Output is correct
25 Correct 1876 ms 2304 KB Output is correct
26 Correct 2035 ms 2308 KB Output is correct
27 Correct 1506 ms 2296 KB Output is correct
28 Correct 1522 ms 2300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 26 ms 1028 KB Output is correct
18 Correct 993 ms 2304 KB Output is correct
19 Correct 1876 ms 2308 KB Output is correct
20 Correct 1 ms 2232 KB Output is correct
21 Correct 27 ms 2260 KB Output is correct
22 Correct 1921 ms 2308 KB Output is correct
23 Correct 1834 ms 2308 KB Output is correct
24 Correct 129 ms 2304 KB Output is correct
25 Correct 1876 ms 2304 KB Output is correct
26 Correct 2035 ms 2308 KB Output is correct
27 Correct 1506 ms 2296 KB Output is correct
28 Correct 1522 ms 2300 KB Output is correct
29 Execution timed out 7093 ms 19540 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 26 ms 1028 KB Output is correct
18 Correct 993 ms 2304 KB Output is correct
19 Correct 1876 ms 2308 KB Output is correct
20 Correct 1 ms 2232 KB Output is correct
21 Correct 27 ms 2260 KB Output is correct
22 Correct 1921 ms 2308 KB Output is correct
23 Correct 1834 ms 2308 KB Output is correct
24 Correct 129 ms 2304 KB Output is correct
25 Correct 1876 ms 2304 KB Output is correct
26 Correct 2035 ms 2308 KB Output is correct
27 Correct 1506 ms 2296 KB Output is correct
28 Correct 1522 ms 2300 KB Output is correct
29 Execution timed out 7093 ms 19540 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 26 ms 1028 KB Output is correct
18 Correct 993 ms 2304 KB Output is correct
19 Correct 1876 ms 2308 KB Output is correct
20 Correct 1 ms 2232 KB Output is correct
21 Correct 27 ms 2260 KB Output is correct
22 Correct 1921 ms 2308 KB Output is correct
23 Correct 1834 ms 2308 KB Output is correct
24 Correct 129 ms 2304 KB Output is correct
25 Correct 1876 ms 2304 KB Output is correct
26 Correct 2035 ms 2308 KB Output is correct
27 Correct 1506 ms 2296 KB Output is correct
28 Correct 1522 ms 2300 KB Output is correct
29 Execution timed out 7093 ms 19540 KB Time limit exceeded
30 Halted 0 ms 0 KB -