Submission #984579

# Submission time Handle Problem Language Result Execution time Memory
984579 2024-05-16T19:50:34 Z DP_196 Visiting Singapore (NOI20_visitingsingapore) C++14
10 / 100
22 ms 32656 KB
#include<bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 1005;
 
int n, m, k, A, B;
 
int f[MAXN][MAXN][2][2], v[MAXN], s[MAXN], t[MAXN];
 
int main() {
	//freopen("funtour.inp", "r", stdin);
	//freopen("funtour.out", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> k >> n >> m >> A >> B;
	
	for (int i = 1; i <= k; i++) cin >> v[i];
	
	for (int i = 1; i <= n; i++) cin >> s[i];
	
	for (int i = 1; i <= m; i++) cin >> t[i];
	
	memset(f, -0x3f, sizeof (f));
	
	int res = -1e9;
	
 
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			f[i][j][0][0] = max({
								f[i - 1][j][0][0], 
								f[i][j - 1][0][0],
								f[i - 1][j][1][0],
								f[i][j - 1][0][1]
								}) + B;
			
			f[i][j][0][0] = max(f[i][j][0][0], f[i - 1][j - 1][1][1] + 2 * B);
			
			f[i][j][0][1] = max(f[i][j][0][1], max(f[i - 1][j][0][1], f[i - 1][j][1][1]) + B);
			f[i][j][1][0] = max(f[i][j][1][0], max(f[i][j - 1][1][0], f[i][j - 1][1][1]) + B);
			
			
			if (s[i] == t[j]) {
				f[i][j][1][1] = max(f[i][j][1][1], (j > 1 ? A : 0) + (j - 1) * B + v[s[i]]);
				
				f[i][j][1][1] = max(f[i][j][1][1], f[i - 1][j - 1][0][0] + 2 * A + v[s[i]]);
				f[i][j][1][1] = max(f[i][j][1][1], f[i - 1][j - 1][0][1] + A + v[s[i]]);
				f[i][j][1][1] = max(f[i][j][1][1], f[i - 1][j - 1][1][0] + A + v[s[i]]);
				f[i][j][1][1] = max(f[i][j][1][1], f[i - 1][j - 1][1][1] + v[s[i]]);
			}
			
			res = max(res, f[i][j][1][1] + (m - j) * B + (j != m ? A : 0));
		} 
	}
	
	cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 16220 KB Output is correct
2 Correct 10 ms 16284 KB Output is correct
3 Correct 5 ms 16220 KB Output is correct
4 Correct 3 ms 16220 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 6 ms 16216 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 3 ms 16220 KB Output is correct
9 Correct 7 ms 16220 KB Output is correct
10 Correct 11 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16220 KB Output is correct
2 Correct 3 ms 16220 KB Output is correct
3 Correct 6 ms 16220 KB Output is correct
4 Correct 4 ms 16220 KB Output is correct
5 Correct 4 ms 16280 KB Output is correct
6 Correct 7 ms 16220 KB Output is correct
7 Correct 7 ms 16284 KB Output is correct
8 Correct 9 ms 16216 KB Output is correct
9 Correct 3 ms 16220 KB Output is correct
10 Correct 11 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 32656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 32656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 32656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16220 KB Output is correct
2 Correct 4 ms 16220 KB Output is correct
3 Correct 3 ms 16220 KB Output is correct
4 Correct 3 ms 16220 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 3 ms 16216 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 3 ms 16216 KB Output is correct
9 Correct 3 ms 16220 KB Output is correct
10 Correct 3 ms 16220 KB Output is correct
11 Correct 3 ms 16220 KB Output is correct
12 Correct 3 ms 16220 KB Output is correct
13 Incorrect 3 ms 16220 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 16220 KB Output is correct
2 Correct 10 ms 16284 KB Output is correct
3 Correct 5 ms 16220 KB Output is correct
4 Correct 3 ms 16220 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 6 ms 16216 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 3 ms 16220 KB Output is correct
9 Correct 7 ms 16220 KB Output is correct
10 Correct 11 ms 16220 KB Output is correct
11 Correct 3 ms 16220 KB Output is correct
12 Correct 3 ms 16220 KB Output is correct
13 Correct 6 ms 16220 KB Output is correct
14 Correct 4 ms 16220 KB Output is correct
15 Correct 4 ms 16280 KB Output is correct
16 Correct 7 ms 16220 KB Output is correct
17 Correct 7 ms 16284 KB Output is correct
18 Correct 9 ms 16216 KB Output is correct
19 Correct 3 ms 16220 KB Output is correct
20 Correct 11 ms 16216 KB Output is correct
21 Runtime error 22 ms 32656 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -