# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
741491 |
2023-05-14T08:54:34 Z |
arnold518 |
Chorus (JOI23_chorus) |
C++17 |
|
7000 ms |
2392 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
const ll INF = 1e12;
int N, K;
char S[MAXN*2+10];
int A[MAXN+10], C[MAXN+10];
ll B[MAXN+10];
ll ans;
ll f(int l, int r)
{
if(C[r]<l) return 0;
return (ll)r*(C[r]-l+1)-(B[C[r]]-B[l-1]);
}
pll dp[MAXN+10];
ll solve(ll lambda)
{
dp[0]={0, 0};
for(int i=1; i<=N; i++)
{
dp[i]={9e18, 0};
for(int j=0; j<i; j++)
{
dp[i]=min(dp[i], {dp[j].first+lambda+2*f(j+1, i), dp[j].second+1});
}
}
return dp[N].second;
}
int main()
{
scanf("%d%d", &N, &K);
scanf(" %s", S+1);
int t=0, k=0;
for(int i=1; i<=N+N; i++)
{
if(S[i]=='A') k++;
else A[++t]=k;
}
for(int i=1; i<=N; i++)
{
if(A[i]<i)
{
ans+=i-A[i];
A[i]=i;
}
B[i]=B[i-1]+A[i];
}
for(int i=1, j=1; i<=N; i++)
{
for(; j<=N && A[j]<i; j++);
C[i]=j-1;
}
ll lo=-1, hi=INF;
while(lo+1<hi)
{
ll mid=lo+hi>>1;
if(solve(mid*2+1)<K) hi=mid;
else lo=mid;
}
solve(hi*2);
printf("%lld\n", ans+dp[N].first/2-K*hi);
}
Compilation message
chorus.cpp: In function 'int main()':
chorus.cpp:69:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | ll mid=lo+hi>>1;
| ~~^~~
chorus.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d%d", &N, &K);
| ~~~~~^~~~~~~~~~~~~~~~
chorus.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf(" %s", S+1);
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
12 ms |
356 KB |
Output is correct |
20 |
Correct |
13 ms |
360 KB |
Output is correct |
21 |
Correct |
13 ms |
340 KB |
Output is correct |
22 |
Correct |
15 ms |
356 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
12 ms |
340 KB |
Output is correct |
25 |
Correct |
12 ms |
356 KB |
Output is correct |
26 |
Correct |
11 ms |
340 KB |
Output is correct |
27 |
Correct |
12 ms |
340 KB |
Output is correct |
28 |
Correct |
12 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
12 ms |
356 KB |
Output is correct |
20 |
Correct |
13 ms |
360 KB |
Output is correct |
21 |
Correct |
13 ms |
340 KB |
Output is correct |
22 |
Correct |
15 ms |
356 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
12 ms |
340 KB |
Output is correct |
25 |
Correct |
12 ms |
356 KB |
Output is correct |
26 |
Correct |
11 ms |
340 KB |
Output is correct |
27 |
Correct |
12 ms |
340 KB |
Output is correct |
28 |
Correct |
12 ms |
304 KB |
Output is correct |
29 |
Correct |
1050 ms |
500 KB |
Output is correct |
30 |
Correct |
1034 ms |
492 KB |
Output is correct |
31 |
Correct |
1045 ms |
500 KB |
Output is correct |
32 |
Correct |
1270 ms |
496 KB |
Output is correct |
33 |
Correct |
1218 ms |
496 KB |
Output is correct |
34 |
Correct |
1090 ms |
492 KB |
Output is correct |
35 |
Correct |
1109 ms |
492 KB |
Output is correct |
36 |
Correct |
1107 ms |
500 KB |
Output is correct |
37 |
Correct |
1079 ms |
496 KB |
Output is correct |
38 |
Correct |
1081 ms |
496 KB |
Output is correct |
39 |
Correct |
1139 ms |
496 KB |
Output is correct |
40 |
Correct |
1052 ms |
488 KB |
Output is correct |
41 |
Correct |
1063 ms |
500 KB |
Output is correct |
42 |
Correct |
1134 ms |
496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
12 ms |
356 KB |
Output is correct |
20 |
Correct |
13 ms |
360 KB |
Output is correct |
21 |
Correct |
13 ms |
340 KB |
Output is correct |
22 |
Correct |
15 ms |
356 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
12 ms |
340 KB |
Output is correct |
25 |
Correct |
12 ms |
356 KB |
Output is correct |
26 |
Correct |
11 ms |
340 KB |
Output is correct |
27 |
Correct |
12 ms |
340 KB |
Output is correct |
28 |
Correct |
12 ms |
304 KB |
Output is correct |
29 |
Correct |
1050 ms |
500 KB |
Output is correct |
30 |
Correct |
1034 ms |
492 KB |
Output is correct |
31 |
Correct |
1045 ms |
500 KB |
Output is correct |
32 |
Correct |
1270 ms |
496 KB |
Output is correct |
33 |
Correct |
1218 ms |
496 KB |
Output is correct |
34 |
Correct |
1090 ms |
492 KB |
Output is correct |
35 |
Correct |
1109 ms |
492 KB |
Output is correct |
36 |
Correct |
1107 ms |
500 KB |
Output is correct |
37 |
Correct |
1079 ms |
496 KB |
Output is correct |
38 |
Correct |
1081 ms |
496 KB |
Output is correct |
39 |
Correct |
1139 ms |
496 KB |
Output is correct |
40 |
Correct |
1052 ms |
488 KB |
Output is correct |
41 |
Correct |
1063 ms |
500 KB |
Output is correct |
42 |
Correct |
1134 ms |
496 KB |
Output is correct |
43 |
Execution timed out |
7043 ms |
2392 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
340 KB |
Output is correct |
19 |
Correct |
12 ms |
356 KB |
Output is correct |
20 |
Correct |
13 ms |
360 KB |
Output is correct |
21 |
Correct |
13 ms |
340 KB |
Output is correct |
22 |
Correct |
15 ms |
356 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
12 ms |
340 KB |
Output is correct |
25 |
Correct |
12 ms |
356 KB |
Output is correct |
26 |
Correct |
11 ms |
340 KB |
Output is correct |
27 |
Correct |
12 ms |
340 KB |
Output is correct |
28 |
Correct |
12 ms |
304 KB |
Output is correct |
29 |
Correct |
1050 ms |
500 KB |
Output is correct |
30 |
Correct |
1034 ms |
492 KB |
Output is correct |
31 |
Correct |
1045 ms |
500 KB |
Output is correct |
32 |
Correct |
1270 ms |
496 KB |
Output is correct |
33 |
Correct |
1218 ms |
496 KB |
Output is correct |
34 |
Correct |
1090 ms |
492 KB |
Output is correct |
35 |
Correct |
1109 ms |
492 KB |
Output is correct |
36 |
Correct |
1107 ms |
500 KB |
Output is correct |
37 |
Correct |
1079 ms |
496 KB |
Output is correct |
38 |
Correct |
1081 ms |
496 KB |
Output is correct |
39 |
Correct |
1139 ms |
496 KB |
Output is correct |
40 |
Correct |
1052 ms |
488 KB |
Output is correct |
41 |
Correct |
1063 ms |
500 KB |
Output is correct |
42 |
Correct |
1134 ms |
496 KB |
Output is correct |
43 |
Execution timed out |
7043 ms |
2392 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |