# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789134 | 2023-07-21T06:04:43 Z | 반딧불(#10041) | Chorus (JOI23_chorus) | C++17 | 7000 ms | 19608 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; void input(); void solve(); int main(){ input(); solve(); } int n, k; ll arr[1000002]; /// A = ( = 1, B = ) = -1 ll revArr[1000002]; /// revArr[x]: arr[i] >= x�� �Ǵ� �ּ� i ll sum[1000002]; char str[2000002]; 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') ++aCnt; else arr[++bCnt] = aCnt; } arr[n+1] = n+1; int pnt = 1; for(int i=arr[1]; i<=n; i++){ while(arr[pnt] < i) pnt++; revArr[i] = pnt; } for(int i=1; i<=n; i++) sum[i] = sum[i-1] + arr[i]; } ll DP[502][502]; ll cost(int s, int e){ int r = min(e, (int)revArr[e] - 1); if(s>r) return 0; return ll(e) * (r-s+1) - (sum[r] - sum[s-1]); } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 0 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 | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 0 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 | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 924 KB | Output is correct |
18 | Correct | 28 ms | 2300 KB | Output is correct |
19 | Correct | 43 ms | 2260 KB | Output is correct |
20 | Correct | 1 ms | 2260 KB | Output is correct |
21 | Correct | 1 ms | 2260 KB | Output is correct |
22 | Correct | 52 ms | 2260 KB | Output is correct |
23 | Correct | 54 ms | 2288 KB | Output is correct |
24 | Correct | 4 ms | 2260 KB | Output is correct |
25 | Correct | 48 ms | 2260 KB | Output is correct |
26 | Correct | 48 ms | 2260 KB | Output is correct |
27 | Correct | 34 ms | 2300 KB | Output is correct |
28 | Correct | 35 ms | 2260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 0 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 | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 924 KB | Output is correct |
18 | Correct | 28 ms | 2300 KB | Output is correct |
19 | Correct | 43 ms | 2260 KB | Output is correct |
20 | Correct | 1 ms | 2260 KB | Output is correct |
21 | Correct | 1 ms | 2260 KB | Output is correct |
22 | Correct | 52 ms | 2260 KB | Output is correct |
23 | Correct | 54 ms | 2288 KB | Output is correct |
24 | Correct | 4 ms | 2260 KB | Output is correct |
25 | Correct | 48 ms | 2260 KB | Output is correct |
26 | Correct | 48 ms | 2260 KB | Output is correct |
27 | Correct | 34 ms | 2300 KB | Output is correct |
28 | Correct | 35 ms | 2260 KB | Output is correct |
29 | Execution timed out | 7089 ms | 19608 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 0 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 | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 924 KB | Output is correct |
18 | Correct | 28 ms | 2300 KB | Output is correct |
19 | Correct | 43 ms | 2260 KB | Output is correct |
20 | Correct | 1 ms | 2260 KB | Output is correct |
21 | Correct | 1 ms | 2260 KB | Output is correct |
22 | Correct | 52 ms | 2260 KB | Output is correct |
23 | Correct | 54 ms | 2288 KB | Output is correct |
24 | Correct | 4 ms | 2260 KB | Output is correct |
25 | Correct | 48 ms | 2260 KB | Output is correct |
26 | Correct | 48 ms | 2260 KB | Output is correct |
27 | Correct | 34 ms | 2300 KB | Output is correct |
28 | Correct | 35 ms | 2260 KB | Output is correct |
29 | Execution timed out | 7089 ms | 19608 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 0 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 | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 924 KB | Output is correct |
18 | Correct | 28 ms | 2300 KB | Output is correct |
19 | Correct | 43 ms | 2260 KB | Output is correct |
20 | Correct | 1 ms | 2260 KB | Output is correct |
21 | Correct | 1 ms | 2260 KB | Output is correct |
22 | Correct | 52 ms | 2260 KB | Output is correct |
23 | Correct | 54 ms | 2288 KB | Output is correct |
24 | Correct | 4 ms | 2260 KB | Output is correct |
25 | Correct | 48 ms | 2260 KB | Output is correct |
26 | Correct | 48 ms | 2260 KB | Output is correct |
27 | Correct | 34 ms | 2300 KB | Output is correct |
28 | Correct | 35 ms | 2260 KB | Output is correct |
29 | Execution timed out | 7089 ms | 19608 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |