Submission #1037703

# Submission time Handle Problem Language Result Execution time Memory
1037703 2024-07-29T07:03:18 Z ㅇㅇ(223.39)(#11011) Chorus (JOI23_chorus) C++17
40 / 100
79 ms 2448 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
const ll inf=1e18;
const int N=505;
int n,k,a[N],m;
string s;
ll S[N];
ll base,dp[N][N];
ll f(int l,int r){
	ll ret=inf;
	for(int p=l+r;p+r-l<=a[r];p++){
		ll c=0;
		for(int i=l;i<=r;i++) c+=max(0,p+i-l-a[i]);
		ret=min(ret,c);
	}
	return ret;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>k>>s;
	for(int i=1;i<=2*n;i++) if(s[i-1]=='B') a[++m]=i;
	for(int i=1;i<=n;i++) if(a[i]<2*i){
		base+=2*i-a[i];
		a[i]=2*i;
	}
	for(int i=1;i<=n;i++) S[i]=S[i-1]+a[i];
	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=inf;
	dp[0][0]=0;
	for(int i=1;i<=n;i++) for(int j=0;j<i;j++){
		ll cost=f(j+1,i);
		debug(j+1,i,cost);
		for(int c=1;c<=j+1;c++) dp[i][c]=min(dp[i][c],dp[j][c-1]+cost);
	}
	cout<<base+dp[n][k];
	return 0;
}

Compilation message

chorus.cpp: In function 'int main()':
chorus.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 42
      |                    ^~
chorus.cpp:40:3: note: in expansion of macro 'debug'
   40 |   debug(j+1,i,cost);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
18 Correct 59 ms 2396 KB Output is correct
19 Correct 79 ms 2396 KB Output is correct
20 Correct 16 ms 2448 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 16 ms 2396 KB Output is correct
23 Correct 16 ms 2396 KB Output is correct
24 Correct 44 ms 2396 KB Output is correct
25 Correct 16 ms 2396 KB Output is correct
26 Correct 16 ms 2396 KB Output is correct
27 Correct 21 ms 2396 KB Output is correct
28 Correct 23 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
18 Correct 59 ms 2396 KB Output is correct
19 Correct 79 ms 2396 KB Output is correct
20 Correct 16 ms 2448 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 16 ms 2396 KB Output is correct
23 Correct 16 ms 2396 KB Output is correct
24 Correct 44 ms 2396 KB Output is correct
25 Correct 16 ms 2396 KB Output is correct
26 Correct 16 ms 2396 KB Output is correct
27 Correct 21 ms 2396 KB Output is correct
28 Correct 23 ms 2396 KB Output is correct
29 Runtime error 1 ms 604 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
18 Correct 59 ms 2396 KB Output is correct
19 Correct 79 ms 2396 KB Output is correct
20 Correct 16 ms 2448 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 16 ms 2396 KB Output is correct
23 Correct 16 ms 2396 KB Output is correct
24 Correct 44 ms 2396 KB Output is correct
25 Correct 16 ms 2396 KB Output is correct
26 Correct 16 ms 2396 KB Output is correct
27 Correct 21 ms 2396 KB Output is correct
28 Correct 23 ms 2396 KB Output is correct
29 Runtime error 1 ms 604 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
18 Correct 59 ms 2396 KB Output is correct
19 Correct 79 ms 2396 KB Output is correct
20 Correct 16 ms 2448 KB Output is correct
21 Correct 16 ms 2396 KB Output is correct
22 Correct 16 ms 2396 KB Output is correct
23 Correct 16 ms 2396 KB Output is correct
24 Correct 44 ms 2396 KB Output is correct
25 Correct 16 ms 2396 KB Output is correct
26 Correct 16 ms 2396 KB Output is correct
27 Correct 21 ms 2396 KB Output is correct
28 Correct 23 ms 2396 KB Output is correct
29 Runtime error 1 ms 604 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -