답안 #224498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224498 2020-04-18T07:43:33 Z Berted Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
572 ms 884 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = -1000069;
int k, n, m, a, b, dp[3][5001][4] = {}, v[1001], s[5001], t[5001];

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> k >> n >> m >> a >> b;
	for (int i = 0; i < k; i++) {cin >> v[i];}
	for (int i = 0; i < n; i++) {cin >> s[i];}
	for (int i = 0; i < m; i++) {cin >> t[i];}
	for (int i = 0; i <= m; i++)
	{
		for (int j = 0; j < 4; j++) {dp[0][i][j] = MN;}
	}
	dp[0][0][0] = 0;
	int ans = a + m * b;
	for (int i = 1; i <= n + m; i++)
	{
		for (int j = 0; j <= i && j <= m; j++)
		{
			for (int l = 0; l < 4; l++) {dp[i % 3][j][l] = MN;}
			int k = i - j;
			if (k > n) {continue;}
			if (j == 0) {dp[i % 3][j][0] = 0;}
			if (j && k && s[k- 1] == t[j - 1])
			{
				//cout << "ENTERED\n";
				for (int l = 0; l < 4; l++)
				{
					if (dp[(i - 2)%3][j - 1][l] != MN) dp[i % 3][j][0] = max(dp[i % 3][j][0], dp[(i - 2)%3][j - 1][l] + v[t[j - 1] - 1]);
				}
			}
			if (j)
			{
				if (dp[(i - 1)%3][j - 1][0] != MN) dp[i % 3][j][1] = max(dp[i % 3][j][1], dp[(i - 1)%3][j - 1][0] + a + b);
				if (dp[(i - 1)%3][j - 1][1] != MN) dp[i % 3][j][1] = max(dp[i % 3][j][1], dp[(i - 1)%3][j - 1][1] + b);
				if (dp[(i - 1)%3][j - 1][2] != MN) dp[i % 3][j][3] = max(dp[i % 3][j][3], dp[(i - 1)%3][j - 1][2] + a + b);
				if (dp[(i - 1)%3][j - 1][3] != MN) dp[i % 3][j][3] = max(dp[i % 3][j][3], dp[(i - 1)%3][j - 1][3] + b);
 			}
			if (k)
			{
				if (dp[(i - 1)%3][j][0] != MN) dp[i % 3][j][2] = max(dp[i % 3][j][2], dp[(i - 1)%3][j][0] + a + b);
				if (dp[(i - 1)%3][j][2] != MN) dp[i % 3][j][2] = max(dp[i % 3][j][2], dp[(i - 1)%3][j][2] + b);
				if (dp[(i - 1)%3][j][1] != MN) dp[i % 3][j][3] = max(dp[i % 3][j][3], dp[(i - 1)%3][j][1] + a + b);
				if (dp[(i - 1)%3][j][3] != MN) dp[i % 3][j][3] = max(dp[i % 3][j][3], dp[(i - 1)%3][j][3] + b);
			}
			if (j == m) 
			{
				ans = max({ans, dp[i % 3][j][0], dp[i % 3][j][1], dp[i % 3][j][2], dp[i % 3][j][3]});
			}
			//cout << j << " "<< k << " " << dp[i % 3][j][0] << " " << dp[i % 3][j][1] << " " << dp[i % 3][j][2] << " " << dp[i % 3][j][3] << "\n";
		}
	}
	cout << ans << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 22 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 15 ms 384 KB Output is correct
10 Correct 26 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 15 ms 384 KB Output is correct
7 Correct 15 ms 384 KB Output is correct
8 Correct 20 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 26 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 384 KB Output is correct
2 Correct 14 ms 460 KB Output is correct
3 Correct 95 ms 512 KB Output is correct
4 Correct 226 ms 632 KB Output is correct
5 Correct 86 ms 632 KB Output is correct
6 Correct 111 ms 512 KB Output is correct
7 Correct 168 ms 632 KB Output is correct
8 Correct 61 ms 512 KB Output is correct
9 Correct 130 ms 512 KB Output is correct
10 Correct 283 ms 632 KB Output is correct
11 Correct 290 ms 632 KB Output is correct
12 Correct 267 ms 632 KB Output is correct
13 Correct 198 ms 632 KB Output is correct
14 Correct 566 ms 636 KB Output is correct
15 Correct 506 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 384 KB Output is correct
2 Correct 14 ms 460 KB Output is correct
3 Correct 95 ms 512 KB Output is correct
4 Correct 226 ms 632 KB Output is correct
5 Correct 86 ms 632 KB Output is correct
6 Correct 111 ms 512 KB Output is correct
7 Correct 168 ms 632 KB Output is correct
8 Correct 61 ms 512 KB Output is correct
9 Correct 130 ms 512 KB Output is correct
10 Correct 283 ms 632 KB Output is correct
11 Correct 290 ms 632 KB Output is correct
12 Correct 267 ms 632 KB Output is correct
13 Correct 198 ms 632 KB Output is correct
14 Correct 566 ms 636 KB Output is correct
15 Correct 506 ms 632 KB Output is correct
16 Correct 155 ms 512 KB Output is correct
17 Correct 192 ms 632 KB Output is correct
18 Correct 148 ms 512 KB Output is correct
19 Correct 40 ms 512 KB Output is correct
20 Correct 109 ms 512 KB Output is correct
21 Correct 11 ms 384 KB Output is correct
22 Correct 47 ms 512 KB Output is correct
23 Correct 81 ms 616 KB Output is correct
24 Correct 28 ms 384 KB Output is correct
25 Correct 285 ms 640 KB Output is correct
26 Correct 268 ms 736 KB Output is correct
27 Correct 283 ms 632 KB Output is correct
28 Correct 197 ms 764 KB Output is correct
29 Correct 512 ms 724 KB Output is correct
30 Correct 563 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 384 KB Output is correct
2 Correct 14 ms 460 KB Output is correct
3 Correct 95 ms 512 KB Output is correct
4 Correct 226 ms 632 KB Output is correct
5 Correct 86 ms 632 KB Output is correct
6 Correct 111 ms 512 KB Output is correct
7 Correct 168 ms 632 KB Output is correct
8 Correct 61 ms 512 KB Output is correct
9 Correct 130 ms 512 KB Output is correct
10 Correct 283 ms 632 KB Output is correct
11 Correct 290 ms 632 KB Output is correct
12 Correct 267 ms 632 KB Output is correct
13 Correct 198 ms 632 KB Output is correct
14 Correct 566 ms 636 KB Output is correct
15 Correct 506 ms 632 KB Output is correct
16 Correct 239 ms 632 KB Output is correct
17 Correct 123 ms 512 KB Output is correct
18 Correct 40 ms 512 KB Output is correct
19 Correct 14 ms 512 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 23 ms 640 KB Output is correct
22 Correct 105 ms 512 KB Output is correct
23 Correct 25 ms 384 KB Output is correct
24 Correct 185 ms 512 KB Output is correct
25 Correct 284 ms 640 KB Output is correct
26 Correct 279 ms 760 KB Output is correct
27 Correct 301 ms 764 KB Output is correct
28 Correct 207 ms 632 KB Output is correct
29 Correct 572 ms 768 KB Output is correct
30 Correct 507 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 22 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 15 ms 384 KB Output is correct
10 Correct 26 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 10 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 15 ms 384 KB Output is correct
17 Correct 15 ms 384 KB Output is correct
18 Correct 20 ms 384 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 26 ms 512 KB Output is correct
21 Correct 30 ms 384 KB Output is correct
22 Correct 14 ms 460 KB Output is correct
23 Correct 95 ms 512 KB Output is correct
24 Correct 226 ms 632 KB Output is correct
25 Correct 86 ms 632 KB Output is correct
26 Correct 111 ms 512 KB Output is correct
27 Correct 168 ms 632 KB Output is correct
28 Correct 61 ms 512 KB Output is correct
29 Correct 130 ms 512 KB Output is correct
30 Correct 283 ms 632 KB Output is correct
31 Correct 290 ms 632 KB Output is correct
32 Correct 267 ms 632 KB Output is correct
33 Correct 198 ms 632 KB Output is correct
34 Correct 566 ms 636 KB Output is correct
35 Correct 506 ms 632 KB Output is correct
36 Correct 155 ms 512 KB Output is correct
37 Correct 192 ms 632 KB Output is correct
38 Correct 148 ms 512 KB Output is correct
39 Correct 40 ms 512 KB Output is correct
40 Correct 109 ms 512 KB Output is correct
41 Correct 11 ms 384 KB Output is correct
42 Correct 47 ms 512 KB Output is correct
43 Correct 81 ms 616 KB Output is correct
44 Correct 28 ms 384 KB Output is correct
45 Correct 285 ms 640 KB Output is correct
46 Correct 268 ms 736 KB Output is correct
47 Correct 283 ms 632 KB Output is correct
48 Correct 197 ms 764 KB Output is correct
49 Correct 512 ms 724 KB Output is correct
50 Correct 563 ms 632 KB Output is correct
51 Correct 239 ms 632 KB Output is correct
52 Correct 123 ms 512 KB Output is correct
53 Correct 40 ms 512 KB Output is correct
54 Correct 14 ms 512 KB Output is correct
55 Correct 10 ms 512 KB Output is correct
56 Correct 23 ms 640 KB Output is correct
57 Correct 105 ms 512 KB Output is correct
58 Correct 25 ms 384 KB Output is correct
59 Correct 185 ms 512 KB Output is correct
60 Correct 284 ms 640 KB Output is correct
61 Correct 279 ms 760 KB Output is correct
62 Correct 301 ms 764 KB Output is correct
63 Correct 207 ms 632 KB Output is correct
64 Correct 572 ms 768 KB Output is correct
65 Correct 507 ms 760 KB Output is correct
66 Correct 4 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 6 ms 384 KB Output is correct
69 Correct 4 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 5 ms 384 KB Output is correct
73 Correct 5 ms 384 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 512 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 5 ms 384 KB Output is correct
80 Correct 5 ms 384 KB Output is correct
81 Correct 234 ms 884 KB Output is correct
82 Correct 58 ms 640 KB Output is correct
83 Correct 106 ms 512 KB Output is correct
84 Correct 61 ms 632 KB Output is correct
85 Correct 94 ms 512 KB Output is correct
86 Correct 75 ms 512 KB Output is correct
87 Correct 17 ms 384 KB Output is correct
88 Correct 13 ms 384 KB Output is correct
89 Correct 35 ms 512 KB Output is correct
90 Correct 351 ms 720 KB Output is correct
91 Correct 264 ms 640 KB Output is correct
92 Correct 281 ms 632 KB Output is correct
93 Correct 273 ms 760 KB Output is correct
94 Correct 299 ms 632 KB Output is correct
95 Correct 211 ms 640 KB Output is correct
96 Correct 266 ms 640 KB Output is correct
97 Correct 263 ms 632 KB Output is correct
98 Correct 503 ms 760 KB Output is correct
99 Correct 510 ms 764 KB Output is correct
100 Correct 556 ms 760 KB Output is correct