답안 #789143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789143 2023-07-21T06:20:57 Z 박상훈(#10042) Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 4308 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
constexpr ll INF = 4e18;
char s[2002000];
int a[1001000], b[1001000], mp[2002000], nxt[2002000];
ll cost[505][505], dp[505][505];

int main(){
	int n, k;
	scanf("%d %d", &n, &k);

	scanf("%s", s+1);
	int ptA = 1, ptB = 1;
	for (int i=1;i<=n*2;i++){
		if (s[i]=='A'){
			mp[i] = ptA;
			a[ptA++] = i;
		} 
		else{
			mp[i] = ptB;
			b[ptB++] = i;
		}
	}

	for (int i=n*2;i;i--){
		if (s[i]=='A') nxt[i] = --ptA;
		else nxt[i] = ptA;
	}

	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			for (int k=i;k<=j;k++){
				cost[i][j] += max(j-nxt[b[k]]+1, 0);
			}
		}
	}

	// is cost monge?
	for (int i=1;i<=n-1;i++){
		for (int j=i+1;j<=n-1;j++){
			assert(cost[i][j] + cost[i+1][j+1] <= cost[i][j+1] + cost[i+1][j]);
		}
	}

	for (int i=0;i<=n;i++){
		fill(dp[i], dp[i]+k+1, INF);
	}
	dp[0][0] = 0;

	for (int i=1;i<=n;i++){
		for (int j=1;j<=k;j++){
			for (int p=0;p<i;p++) dp[i][j] = min(dp[i][j], dp[p][j-1] + cost[p+1][i]);
		}
	}

	printf("%lld\n", dp[n][k]);
}

Compilation message

chorus.cpp: In function 'int main()':
chorus.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d %d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~
chorus.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%s", s+1);
      |  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 340 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 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 340 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 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 34 ms 4304 KB Output is correct
19 Correct 63 ms 4260 KB Output is correct
20 Correct 21 ms 4300 KB Output is correct
21 Correct 21 ms 4200 KB Output is correct
22 Correct 102 ms 4188 KB Output is correct
23 Correct 105 ms 4292 KB Output is correct
24 Correct 23 ms 4192 KB Output is correct
25 Correct 100 ms 4308 KB Output is correct
26 Correct 98 ms 4292 KB Output is correct
27 Correct 45 ms 4212 KB Output is correct
28 Correct 46 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 340 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 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 34 ms 4304 KB Output is correct
19 Correct 63 ms 4260 KB Output is correct
20 Correct 21 ms 4300 KB Output is correct
21 Correct 21 ms 4200 KB Output is correct
22 Correct 102 ms 4188 KB Output is correct
23 Correct 105 ms 4292 KB Output is correct
24 Correct 23 ms 4192 KB Output is correct
25 Correct 100 ms 4308 KB Output is correct
26 Correct 98 ms 4292 KB Output is correct
27 Correct 45 ms 4212 KB Output is correct
28 Correct 46 ms 4180 KB Output is correct
29 Execution timed out 7029 ms 3648 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 340 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 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 34 ms 4304 KB Output is correct
19 Correct 63 ms 4260 KB Output is correct
20 Correct 21 ms 4300 KB Output is correct
21 Correct 21 ms 4200 KB Output is correct
22 Correct 102 ms 4188 KB Output is correct
23 Correct 105 ms 4292 KB Output is correct
24 Correct 23 ms 4192 KB Output is correct
25 Correct 100 ms 4308 KB Output is correct
26 Correct 98 ms 4292 KB Output is correct
27 Correct 45 ms 4212 KB Output is correct
28 Correct 46 ms 4180 KB Output is correct
29 Execution timed out 7029 ms 3648 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 340 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 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 3 ms 1748 KB Output is correct
18 Correct 34 ms 4304 KB Output is correct
19 Correct 63 ms 4260 KB Output is correct
20 Correct 21 ms 4300 KB Output is correct
21 Correct 21 ms 4200 KB Output is correct
22 Correct 102 ms 4188 KB Output is correct
23 Correct 105 ms 4292 KB Output is correct
24 Correct 23 ms 4192 KB Output is correct
25 Correct 100 ms 4308 KB Output is correct
26 Correct 98 ms 4292 KB Output is correct
27 Correct 45 ms 4212 KB Output is correct
28 Correct 46 ms 4180 KB Output is correct
29 Execution timed out 7029 ms 3648 KB Time limit exceeded
30 Halted 0 ms 0 KB -