Submission #947365

# Submission time Handle Problem Language Result Execution time Memory
947365 2024-03-16T03:15:52 Z firewater Chorus (JOI23_chorus) C++14
61 / 100
7000 ms 11356 KB
#include<bits/stdc++.h>
#define ll long long
#define N 2024000
using namespace std;
ll n,k,x,now,l,r,a[N],sum[N],v[N],f[N],s[N];
char ss[N];
ll ask(ll k)
{
	for(ll i=1;i<=n;++i)
		f[i]=1000000000000ll,s[i]=0;
    f[0]=0,s[0]=0;
	for(ll i=1;i<=n;++i)
		for(ll j=0;j<i;++j)
            if(make_pair(f[j]+sum[i]-sum[v[j+1]]-j*(i-v[j+1])+k,s[j]+1)<make_pair(f[i],s[i])){
				f[i]=f[j]+sum[i]-sum[v[j+1]]-j*(i-v[j+1])+k;
				s[i]=s[j]+1;
			}
	return s[n];
}
signed main()
{
	scanf("%lld%lld%s",&n,&k,ss+1);
	x=now=0;
	for(ll i=1;i<=n*2;++i){
		if(ss[i]=='A'){
			a[++x]=now;
			sum[x]=sum[x-1]+a[x];
		}
		else now++,v[now]=max(now-1,x);
	}
	l=0;
	r=1000000000000ll;
	while(l<r){
		ll mid=l+r>>1;
		if(ask(mid)<=k)r=mid;
		else l=mid+1;
	}
    x=ask(l);
    printf("%lld\n",f[n]-l*k);
    return 0;
}

Compilation message

chorus.cpp: In function 'int main()':
chorus.cpp:34:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |   ll mid=l+r>>1;
      |          ~^~
chorus.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%lld%lld%s",&n,&k,ss+1);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 8 ms 8540 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 8 ms 8660 KB Output is correct
21 Correct 8 ms 8540 KB Output is correct
22 Correct 8 ms 8540 KB Output is correct
23 Correct 8 ms 8664 KB Output is correct
24 Correct 8 ms 8540 KB Output is correct
25 Correct 8 ms 8664 KB Output is correct
26 Correct 8 ms 8536 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 11 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 8 ms 8540 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 8 ms 8660 KB Output is correct
21 Correct 8 ms 8540 KB Output is correct
22 Correct 8 ms 8540 KB Output is correct
23 Correct 8 ms 8664 KB Output is correct
24 Correct 8 ms 8540 KB Output is correct
25 Correct 8 ms 8664 KB Output is correct
26 Correct 8 ms 8536 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 11 ms 8652 KB Output is correct
29 Correct 627 ms 8688 KB Output is correct
30 Correct 667 ms 8692 KB Output is correct
31 Correct 663 ms 8540 KB Output is correct
32 Correct 664 ms 8536 KB Output is correct
33 Correct 653 ms 8688 KB Output is correct
34 Correct 701 ms 8688 KB Output is correct
35 Correct 659 ms 8692 KB Output is correct
36 Correct 653 ms 8788 KB Output is correct
37 Correct 670 ms 8788 KB Output is correct
38 Correct 687 ms 8696 KB Output is correct
39 Correct 704 ms 8692 KB Output is correct
40 Correct 669 ms 8540 KB Output is correct
41 Correct 666 ms 8692 KB Output is correct
42 Correct 674 ms 8688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 8 ms 8540 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 8 ms 8660 KB Output is correct
21 Correct 8 ms 8540 KB Output is correct
22 Correct 8 ms 8540 KB Output is correct
23 Correct 8 ms 8664 KB Output is correct
24 Correct 8 ms 8540 KB Output is correct
25 Correct 8 ms 8664 KB Output is correct
26 Correct 8 ms 8536 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 11 ms 8652 KB Output is correct
29 Correct 627 ms 8688 KB Output is correct
30 Correct 667 ms 8692 KB Output is correct
31 Correct 663 ms 8540 KB Output is correct
32 Correct 664 ms 8536 KB Output is correct
33 Correct 653 ms 8688 KB Output is correct
34 Correct 701 ms 8688 KB Output is correct
35 Correct 659 ms 8692 KB Output is correct
36 Correct 653 ms 8788 KB Output is correct
37 Correct 670 ms 8788 KB Output is correct
38 Correct 687 ms 8696 KB Output is correct
39 Correct 704 ms 8692 KB Output is correct
40 Correct 669 ms 8540 KB Output is correct
41 Correct 666 ms 8692 KB Output is correct
42 Correct 674 ms 8688 KB Output is correct
43 Execution timed out 7058 ms 11356 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 8 ms 8540 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 8 ms 8660 KB Output is correct
21 Correct 8 ms 8540 KB Output is correct
22 Correct 8 ms 8540 KB Output is correct
23 Correct 8 ms 8664 KB Output is correct
24 Correct 8 ms 8540 KB Output is correct
25 Correct 8 ms 8664 KB Output is correct
26 Correct 8 ms 8536 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 11 ms 8652 KB Output is correct
29 Correct 627 ms 8688 KB Output is correct
30 Correct 667 ms 8692 KB Output is correct
31 Correct 663 ms 8540 KB Output is correct
32 Correct 664 ms 8536 KB Output is correct
33 Correct 653 ms 8688 KB Output is correct
34 Correct 701 ms 8688 KB Output is correct
35 Correct 659 ms 8692 KB Output is correct
36 Correct 653 ms 8788 KB Output is correct
37 Correct 670 ms 8788 KB Output is correct
38 Correct 687 ms 8696 KB Output is correct
39 Correct 704 ms 8692 KB Output is correct
40 Correct 669 ms 8540 KB Output is correct
41 Correct 666 ms 8692 KB Output is correct
42 Correct 674 ms 8688 KB Output is correct
43 Execution timed out 7058 ms 11356 KB Time limit exceeded
44 Halted 0 ms 0 KB -