답안 #889921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889921 2023-12-20T09:47:49 Z TAhmed33 Copy and Paste 3 (JOI22_copypaste3) C++
15 / 100
3000 ms 9052 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[31][31][31][31];
bool pre[31][31][31][31];
string s; ll a, b, c, n;
ll ans (int l1, int r1, int l2, int r2) {
	ll &ret = dp[l1][r1][l2][r2];
	if (ret != -1) return ret;
	/*cout << (l1 == 0 ? "?" : s.substr(l1, r1 - l1 + 1)) << " ";
	cout << (l2 == 0 ? "?" : s.substr(l2, r2 - l2 + 1)) << " ";	 
	cout << '\n';*/
	if (l1 == 1 && r1 == n) return ret = 0;
	ret = 1e18;
	if (l1 && r1 != n) ret = min(ret, a + ans(l1, r1 + 1, l2, r2));
	if (!l1) {
		for (int i = 1; i <= n; i++) ret = min(ret, a + ans(i, i, l2, r2));	
	}
	if (l1) ret = min(ret, b + ans(0, 0, l1, r1));
	if (l1 && l2 && r1 + (r2 - l2 + 1) <= n && pre[r1 + 1][r1 + r2 - l2 + 1][l2][r2]) {
		ret = min(ret, c + ans(l1, r1 + r2 - l2 + 1, l2, r2));
	}
	if (!l1 && l2) {
		for (int i = 1; i + (r2 - l2) <= n; i++) {
			if (pre[i][i + r2 - l2][l2][r2]) ret = min(ret, c + ans(i, i + r2 - l2, l2, r2));
		}
	}
	return ret;
}
int main () {
	memset(dp, -1, sizeof(dp));
	cin >> n >> s >> a >> b >> c;
	s.insert(s.begin(), '0');
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			for (int l = 1; l <= n; l++) {
				for (int m = l; m <= n; m++) {
					if (m - l != j - i) continue;
					pre	[i][j][l][m] = 1;
					for (int t = i; t <= j; t++) {
						pre[i][j][l][m] &= s[t] == s[l + t - i];
					}
				}
			}
		}
	}
	cout << ans(0, 0, 0, 0) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8396 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Execution timed out 3097 ms 8472 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8520 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 6 ms 9052 KB Output is correct
23 Correct 5 ms 8892 KB Output is correct
24 Correct 5 ms 8888 KB Output is correct
25 Correct 5 ms 8908 KB Output is correct
26 Correct 5 ms 9052 KB Output is correct
27 Correct 5 ms 9052 KB Output is correct
28 Correct 5 ms 9052 KB Output is correct
29 Correct 6 ms 8904 KB Output is correct
30 Correct 5 ms 9052 KB Output is correct
31 Correct 5 ms 9052 KB Output is correct
32 Correct 5 ms 9052 KB Output is correct
33 Correct 5 ms 8796 KB Output is correct
34 Correct 2 ms 8284 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8284 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 5 ms 9020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8520 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 6 ms 9052 KB Output is correct
23 Correct 5 ms 8892 KB Output is correct
24 Correct 5 ms 8888 KB Output is correct
25 Correct 5 ms 8908 KB Output is correct
26 Correct 5 ms 9052 KB Output is correct
27 Correct 5 ms 9052 KB Output is correct
28 Correct 5 ms 9052 KB Output is correct
29 Correct 6 ms 8904 KB Output is correct
30 Correct 5 ms 9052 KB Output is correct
31 Correct 5 ms 9052 KB Output is correct
32 Correct 5 ms 9052 KB Output is correct
33 Correct 5 ms 8796 KB Output is correct
34 Correct 2 ms 8284 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8284 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 5 ms 9020 KB Output is correct
40 Incorrect 17 ms 8540 KB Output isn't correct
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8520 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 6 ms 9052 KB Output is correct
23 Correct 5 ms 8892 KB Output is correct
24 Correct 5 ms 8888 KB Output is correct
25 Correct 5 ms 8908 KB Output is correct
26 Correct 5 ms 9052 KB Output is correct
27 Correct 5 ms 9052 KB Output is correct
28 Correct 5 ms 9052 KB Output is correct
29 Correct 6 ms 8904 KB Output is correct
30 Correct 5 ms 9052 KB Output is correct
31 Correct 5 ms 9052 KB Output is correct
32 Correct 5 ms 9052 KB Output is correct
33 Correct 5 ms 8796 KB Output is correct
34 Correct 2 ms 8284 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8284 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 5 ms 9020 KB Output is correct
40 Incorrect 17 ms 8540 KB Output isn't correct
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8280 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8284 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8396 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Execution timed out 3097 ms 8472 KB Time limit exceeded
14 Halted 0 ms 0 KB -