답안 #950481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950481 2024-03-20T11:00:21 Z andrei_boaca Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 59964 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF=1e17;
ll n,k,lga,lgb,makegood;
ll A[1000005],B[1000005];
ll dp[5005][5005];
string str;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    cin>>str;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]=='A')
            A[++lga]=i+1;
        else
            B[++lgb]=i+1;
    }
    for(int i=1;i<=n;i++)
        if(A[i]>B[i])
        {
            ll x=A[i];
            A[i]=B[i];
            for(int j=i;j<=n;j++)
            {
                if(B[j]<x)
                {
                    B[j]++;
                    makegood++;
                }
                else
                    break;
            }
        }
    for(int i=n;i>=1;i--)
    {
        dp[i][0]=INF;
        for(int cnt=1;cnt<=k;cnt++)
        {
            ll suma=0;
            ll cost=0;
            int ind=i;
            dp[i][cnt]=dp[i+1][cnt-1];
            for(int j=i+1;j<=n;j++)
            {
                while(ind<=n&&B[ind]<A[j])
                {
                    suma++;
                    ind++;
                }
                cost+=suma;
                dp[i][cnt]=min(dp[i][cnt],cost+dp[j+1][cnt-1]);
            }
        }
    }
    cout<<dp[1][k]+makegood;
    return 0;
}

Compilation message

chorus.cpp: In function 'int main()':
chorus.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i=0;i<str.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6604 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6604 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 35 ms 25168 KB Output is correct
19 Correct 83 ms 25056 KB Output is correct
20 Correct 3 ms 24924 KB Output is correct
21 Correct 4 ms 25044 KB Output is correct
22 Correct 110 ms 25052 KB Output is correct
23 Correct 108 ms 25068 KB Output is correct
24 Correct 7 ms 24924 KB Output is correct
25 Correct 108 ms 25052 KB Output is correct
26 Correct 91 ms 25064 KB Output is correct
27 Correct 50 ms 25056 KB Output is correct
28 Correct 38 ms 24912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6604 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 35 ms 25168 KB Output is correct
19 Correct 83 ms 25056 KB Output is correct
20 Correct 3 ms 24924 KB Output is correct
21 Correct 4 ms 25044 KB Output is correct
22 Correct 110 ms 25052 KB Output is correct
23 Correct 108 ms 25068 KB Output is correct
24 Correct 7 ms 24924 KB Output is correct
25 Correct 108 ms 25052 KB Output is correct
26 Correct 91 ms 25064 KB Output is correct
27 Correct 50 ms 25056 KB Output is correct
28 Correct 38 ms 24912 KB Output is correct
29 Execution timed out 7018 ms 59964 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6604 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 35 ms 25168 KB Output is correct
19 Correct 83 ms 25056 KB Output is correct
20 Correct 3 ms 24924 KB Output is correct
21 Correct 4 ms 25044 KB Output is correct
22 Correct 110 ms 25052 KB Output is correct
23 Correct 108 ms 25068 KB Output is correct
24 Correct 7 ms 24924 KB Output is correct
25 Correct 108 ms 25052 KB Output is correct
26 Correct 91 ms 25064 KB Output is correct
27 Correct 50 ms 25056 KB Output is correct
28 Correct 38 ms 24912 KB Output is correct
29 Execution timed out 7018 ms 59964 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6604 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 35 ms 25168 KB Output is correct
19 Correct 83 ms 25056 KB Output is correct
20 Correct 3 ms 24924 KB Output is correct
21 Correct 4 ms 25044 KB Output is correct
22 Correct 110 ms 25052 KB Output is correct
23 Correct 108 ms 25068 KB Output is correct
24 Correct 7 ms 24924 KB Output is correct
25 Correct 108 ms 25052 KB Output is correct
26 Correct 91 ms 25064 KB Output is correct
27 Correct 50 ms 25056 KB Output is correct
28 Correct 38 ms 24912 KB Output is correct
29 Execution timed out 7018 ms 59964 KB Time limit exceeded
30 Halted 0 ms 0 KB -