# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935046 | 2024-02-28T13:06:33 Z | kim | Chorus (JOI23_chorus) | C++17 | 7000 ms | 144360 KB |
#include<bits/stdc++.h> using namespace std; using ll=long long; const ll inf=1e18; int a[5005],b[5005],pos[5005]; ll dp[5005][5005],cost[5005][5005]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,K; cin>>n>>K; string s; cin>>s; for(int i=0,ia=0,ib=0;i<s.length();++i){ if(s[i]=='A') a[++ia]=i; else b[++ib]=i; } for(int i=1,j=1;i<=n;++i){ while(j<=n&&b[j]<a[i]) ++j; pos[i]=j; } for(int i=1;i<=n;++i){ for(int j=i;j<=n;++j){ cost[i][j]=cost[i][j-1]+max(0,pos[j]-i); } } for(int i=1;i<=n;++i) dp[1][i]=cost[1][i]; for(int k=2;k<=K;++k){ for(int i=k;i<=n;++i){ dp[k][i]=inf; for(int j=k-1;j<i;++j){ dp[k][i]=min(dp[k][i],dp[k-1][j]+cost[j+1][i]); } } } cout<<dp[K][n]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 2 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 0 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 2 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 0 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 3 ms | 5212 KB | Output is correct |
18 | Correct | 14 ms | 11376 KB | Output is correct |
19 | Correct | 23 ms | 17280 KB | Output is correct |
20 | Correct | 2 ms | 7260 KB | Output is correct |
21 | Correct | 2 ms | 7260 KB | Output is correct |
22 | Correct | 27 ms | 27732 KB | Output is correct |
23 | Correct | 26 ms | 27740 KB | Output is correct |
24 | Correct | 4 ms | 7260 KB | Output is correct |
25 | Correct | 30 ms | 27628 KB | Output is correct |
26 | Correct | 26 ms | 23660 KB | Output is correct |
27 | Correct | 18 ms | 13392 KB | Output is correct |
28 | Correct | 18 ms | 13332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 2 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 0 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 3 ms | 5212 KB | Output is correct |
18 | Correct | 14 ms | 11376 KB | Output is correct |
19 | Correct | 23 ms | 17280 KB | Output is correct |
20 | Correct | 2 ms | 7260 KB | Output is correct |
21 | Correct | 2 ms | 7260 KB | Output is correct |
22 | Correct | 27 ms | 27732 KB | Output is correct |
23 | Correct | 26 ms | 27740 KB | Output is correct |
24 | Correct | 4 ms | 7260 KB | Output is correct |
25 | Correct | 30 ms | 27628 KB | Output is correct |
26 | Correct | 26 ms | 23660 KB | Output is correct |
27 | Correct | 18 ms | 13392 KB | Output is correct |
28 | Correct | 18 ms | 13332 KB | Output is correct |
29 | Execution timed out | 7019 ms | 144360 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 2 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 0 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 3 ms | 5212 KB | Output is correct |
18 | Correct | 14 ms | 11376 KB | Output is correct |
19 | Correct | 23 ms | 17280 KB | Output is correct |
20 | Correct | 2 ms | 7260 KB | Output is correct |
21 | Correct | 2 ms | 7260 KB | Output is correct |
22 | Correct | 27 ms | 27732 KB | Output is correct |
23 | Correct | 26 ms | 27740 KB | Output is correct |
24 | Correct | 4 ms | 7260 KB | Output is correct |
25 | Correct | 30 ms | 27628 KB | Output is correct |
26 | Correct | 26 ms | 23660 KB | Output is correct |
27 | Correct | 18 ms | 13392 KB | Output is correct |
28 | Correct | 18 ms | 13332 KB | Output is correct |
29 | Execution timed out | 7019 ms | 144360 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 2 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 0 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 3 ms | 5212 KB | Output is correct |
18 | Correct | 14 ms | 11376 KB | Output is correct |
19 | Correct | 23 ms | 17280 KB | Output is correct |
20 | Correct | 2 ms | 7260 KB | Output is correct |
21 | Correct | 2 ms | 7260 KB | Output is correct |
22 | Correct | 27 ms | 27732 KB | Output is correct |
23 | Correct | 26 ms | 27740 KB | Output is correct |
24 | Correct | 4 ms | 7260 KB | Output is correct |
25 | Correct | 30 ms | 27628 KB | Output is correct |
26 | Correct | 26 ms | 23660 KB | Output is correct |
27 | Correct | 18 ms | 13392 KB | Output is correct |
28 | Correct | 18 ms | 13332 KB | Output is correct |
29 | Execution timed out | 7019 ms | 144360 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |