답안 #984677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984677 2024-05-17T01:44:15 Z DP_196 Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
278 ms 856 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define sz(x) (int)x.size()
#define MASK(i) ((1LL) << (i))
#define all(x) x.begin(), x.end()
#define BIT(x, i) ((x) >> (i) & (1LL))
#define dbg(...) cerr << "#" << __LINE__ << ":[" << #__VA_ARGS__ \
<< "] = [" ,DBG(__VA_ARGS__)
 
string to_string(const string& s) { return '"' + s + '"'; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
        cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...);
}
 
template <class T>
inline bool maximize(T &a, const T &b) { return (a < b ? (a = b) : 0); }
template <class T>
inline bool minimize(T &a, const T &b) { return (a > b ? (a = b) : 0); }
 
const int MAXN = 1e5 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;
 
int k, n, m, a, b, v[5005], s[5005], t[5005];
int dp[2][5005][2][2];
 
void subAC() {
	int res = a + m * b;
	
	memset(dp, -0x3f, sizeof (dp));
	
	int inf = dp[0][0][0][0];
 
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) { 
			dp[1][j][0][0] = max({dp[0][j][0][0] + b, dp[1][j - 1][0][0] + b, dp[0][j - 1][1][1] + 2 * b
				, dp[0][j][1][0] + b, dp[1][j - 1][0][1] + b});
			dp[1][j][0][1] = max(dp[0][j][0][1], dp[0][j][1][1]) + b;
			dp[1][j][1][0] = max(dp[1][j - 1][1][0], dp[1][j - 1][1][1]) + b;
			
			if (s[i] == t[j]) {
				dp[1][j][1][1] = v[s[i]] + (j > 1 ? a + (j - 1) * b : 0);
				maximize(dp[1][j][1][1], dp[0][j - 1][0][0] + 2 * a + v[s[i]]);
				maximize(dp[1][j][1][1], dp[0][j - 1][0][1] + a + v[s[i]]);
				maximize(dp[1][j][1][1], dp[0][j - 1][1][0] + a + v[s[i]]);
				maximize(dp[1][j][1][1], dp[0][j - 1][1][1] + v[s[i]]);
			}
			
			maximize(res, dp[1][j][1][1] + (m - j >= 1 ? a + (m - j) * b : 0));
		}
		
		for (int j = 0; j <= m; j++) {
			dp[0][j][0][0] = dp[1][j][0][0]; dp[1][j][0][0] = inf;
			dp[0][j][0][1] = dp[1][j][0][1]; dp[1][j][0][1] = inf;
			dp[0][j][1][0] = dp[1][j][1][0]; dp[1][j][1][0] = inf;
			dp[0][j][1][1] = dp[1][j][1][1]; dp[1][j][1][1] = inf;
		}
	}
	
	cout << res;
}                     
 
void solve() {
	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];
	
	subAC();
}
 
#define TASK "FUNTOUR"
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   	//freopen(TASK".inp", "r", stdin);
   	//freopen(TASK".out", "w", stdout);
 
    int ntest = 1;
    //cin >> ntest;
    while (ntest--) solve();
 
    return 0;
}
//612
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 10 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 5 ms 636 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 7 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 10 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 652 KB Output is correct
2 Correct 9 ms 600 KB Output is correct
3 Correct 78 ms 644 KB Output is correct
4 Correct 176 ms 668 KB Output is correct
5 Correct 54 ms 604 KB Output is correct
6 Correct 75 ms 644 KB Output is correct
7 Correct 139 ms 660 KB Output is correct
8 Correct 46 ms 604 KB Output is correct
9 Correct 89 ms 660 KB Output is correct
10 Correct 232 ms 672 KB Output is correct
11 Correct 224 ms 852 KB Output is correct
12 Correct 219 ms 676 KB Output is correct
13 Correct 218 ms 604 KB Output is correct
14 Correct 238 ms 664 KB Output is correct
15 Correct 235 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 652 KB Output is correct
2 Correct 9 ms 600 KB Output is correct
3 Correct 78 ms 644 KB Output is correct
4 Correct 176 ms 668 KB Output is correct
5 Correct 54 ms 604 KB Output is correct
6 Correct 75 ms 644 KB Output is correct
7 Correct 139 ms 660 KB Output is correct
8 Correct 46 ms 604 KB Output is correct
9 Correct 89 ms 660 KB Output is correct
10 Correct 232 ms 672 KB Output is correct
11 Correct 224 ms 852 KB Output is correct
12 Correct 219 ms 676 KB Output is correct
13 Correct 218 ms 604 KB Output is correct
14 Correct 238 ms 664 KB Output is correct
15 Correct 235 ms 604 KB Output is correct
16 Correct 115 ms 664 KB Output is correct
17 Correct 143 ms 664 KB Output is correct
18 Correct 123 ms 604 KB Output is correct
19 Correct 25 ms 604 KB Output is correct
20 Correct 88 ms 856 KB Output is correct
21 Correct 6 ms 604 KB Output is correct
22 Correct 28 ms 604 KB Output is correct
23 Correct 57 ms 648 KB Output is correct
24 Correct 20 ms 600 KB Output is correct
25 Correct 221 ms 604 KB Output is correct
26 Correct 219 ms 676 KB Output is correct
27 Correct 226 ms 668 KB Output is correct
28 Correct 237 ms 804 KB Output is correct
29 Correct 252 ms 848 KB Output is correct
30 Correct 243 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 652 KB Output is correct
2 Correct 9 ms 600 KB Output is correct
3 Correct 78 ms 644 KB Output is correct
4 Correct 176 ms 668 KB Output is correct
5 Correct 54 ms 604 KB Output is correct
6 Correct 75 ms 644 KB Output is correct
7 Correct 139 ms 660 KB Output is correct
8 Correct 46 ms 604 KB Output is correct
9 Correct 89 ms 660 KB Output is correct
10 Correct 232 ms 672 KB Output is correct
11 Correct 224 ms 852 KB Output is correct
12 Correct 219 ms 676 KB Output is correct
13 Correct 218 ms 604 KB Output is correct
14 Correct 238 ms 664 KB Output is correct
15 Correct 235 ms 604 KB Output is correct
16 Correct 204 ms 664 KB Output is correct
17 Correct 90 ms 600 KB Output is correct
18 Correct 30 ms 604 KB Output is correct
19 Correct 9 ms 644 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 6 ms 600 KB Output is correct
22 Correct 86 ms 660 KB Output is correct
23 Correct 18 ms 604 KB Output is correct
24 Correct 157 ms 652 KB Output is correct
25 Correct 218 ms 684 KB Output is correct
26 Correct 226 ms 664 KB Output is correct
27 Correct 232 ms 680 KB Output is correct
28 Correct 218 ms 664 KB Output is correct
29 Correct 237 ms 604 KB Output is correct
30 Correct 278 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 10 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 5 ms 636 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 7 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 10 ms 632 KB Output is correct
21 Correct 22 ms 652 KB Output is correct
22 Correct 9 ms 600 KB Output is correct
23 Correct 78 ms 644 KB Output is correct
24 Correct 176 ms 668 KB Output is correct
25 Correct 54 ms 604 KB Output is correct
26 Correct 75 ms 644 KB Output is correct
27 Correct 139 ms 660 KB Output is correct
28 Correct 46 ms 604 KB Output is correct
29 Correct 89 ms 660 KB Output is correct
30 Correct 232 ms 672 KB Output is correct
31 Correct 224 ms 852 KB Output is correct
32 Correct 219 ms 676 KB Output is correct
33 Correct 218 ms 604 KB Output is correct
34 Correct 238 ms 664 KB Output is correct
35 Correct 235 ms 604 KB Output is correct
36 Correct 115 ms 664 KB Output is correct
37 Correct 143 ms 664 KB Output is correct
38 Correct 123 ms 604 KB Output is correct
39 Correct 25 ms 604 KB Output is correct
40 Correct 88 ms 856 KB Output is correct
41 Correct 6 ms 604 KB Output is correct
42 Correct 28 ms 604 KB Output is correct
43 Correct 57 ms 648 KB Output is correct
44 Correct 20 ms 600 KB Output is correct
45 Correct 221 ms 604 KB Output is correct
46 Correct 219 ms 676 KB Output is correct
47 Correct 226 ms 668 KB Output is correct
48 Correct 237 ms 804 KB Output is correct
49 Correct 252 ms 848 KB Output is correct
50 Correct 243 ms 604 KB Output is correct
51 Correct 204 ms 664 KB Output is correct
52 Correct 90 ms 600 KB Output is correct
53 Correct 30 ms 604 KB Output is correct
54 Correct 9 ms 644 KB Output is correct
55 Correct 4 ms 604 KB Output is correct
56 Correct 6 ms 600 KB Output is correct
57 Correct 86 ms 660 KB Output is correct
58 Correct 18 ms 604 KB Output is correct
59 Correct 157 ms 652 KB Output is correct
60 Correct 218 ms 684 KB Output is correct
61 Correct 226 ms 664 KB Output is correct
62 Correct 232 ms 680 KB Output is correct
63 Correct 218 ms 664 KB Output is correct
64 Correct 237 ms 604 KB Output is correct
65 Correct 278 ms 604 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 0 ms 604 KB Output is correct
68 Correct 0 ms 604 KB Output is correct
69 Correct 1 ms 604 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 0 ms 604 KB Output is correct
74 Correct 1 ms 856 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 0 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 600 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 175 ms 692 KB Output is correct
82 Correct 41 ms 604 KB Output is correct
83 Correct 86 ms 604 KB Output is correct
84 Correct 43 ms 600 KB Output is correct
85 Correct 70 ms 604 KB Output is correct
86 Correct 60 ms 604 KB Output is correct
87 Correct 11 ms 604 KB Output is correct
88 Correct 8 ms 604 KB Output is correct
89 Correct 25 ms 604 KB Output is correct
90 Correct 250 ms 604 KB Output is correct
91 Correct 222 ms 668 KB Output is correct
92 Correct 223 ms 852 KB Output is correct
93 Correct 220 ms 604 KB Output is correct
94 Correct 223 ms 668 KB Output is correct
95 Correct 223 ms 656 KB Output is correct
96 Correct 221 ms 604 KB Output is correct
97 Correct 222 ms 604 KB Output is correct
98 Correct 240 ms 756 KB Output is correct
99 Correct 265 ms 604 KB Output is correct
100 Correct 244 ms 852 KB Output is correct