Submission #1091939

# Submission time Handle Problem Language Result Execution time Memory
1091939 2024-09-22T16:19:08 Z _rain_ Visiting Singapore (NOI20_visitingsingapore) C++14
29 / 100
234 ms 856 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fixbug true
 
const ll INF = (ll)1e18+7;
const int maxn = 5e3;
int K , n , m ;
ll A , B;
int s[maxn+2] , t[maxn+2] ;
ll v[maxn+2];
 
namespace subtask1{
	bool check(){
		return K==1;
	}
	void main_code(){
		if (n < m){
			cout << n * v[1] + B * (m - n) + A;
			exit(0);
		}
		cout << m * v[1] << '\n';
		exit(0);	
	}
}
namespace subtask2{
	bool check(){
		return true;
	}
	ll sub(int x1 , int x , int y1 , int y){
		// x for T , y for S
		return A*(x1+y1) + B*(y+x);
	}
	// dp[S][T][MATCH/NOT] 
	ll dp[maxn+2][2] , f[maxn+2][2] , tam[maxn+2] , cot[maxn+2]={};
	void main_code(){
		memset(dp,-0x3f,sizeof dp);
		memset(tam,-0x3f,sizeof tam);
		for (int i = 0; i <= n; ++i){
			dp[i][1] = 0;
		}
		ll ans = -INF;
		for (int layer = 1; layer <= m; ++layer) // T for 
		{
			for (int i = 0; i <= n; ++i){
				tam[i] = -INF;
				f[i][0] = dp[i][0] , f[i][1] = dp[i][1];
				dp[i][0] = dp[i][1] = -INF;
			}
			for (int i = 1; i <= n; ++i) // S for 
			{
				if (s[i] == t[layer])
				{
					dp[i][1] = max({
						f[i-1][1] , f[i-1][0] , cot[i] , tam[i-1]
					}) + v[t[layer]];
				}
				dp[i][0] = max({
					f[i-1][1] + sub(1,1,1,1),
					f[i-1][0] + sub(0,1,0,1),
					f[i][0] + sub(0,0,0,1),
					f[i][1] + sub(0,0,1,1),
					dp[i-1][0] + sub(0,1,0,0),
					dp[i-1][1] + sub(1,1,0,0)
				});
				tam[i] = max({
					f[i-1][1] + sub(1,1,1,1),
					f[i-1][0] + sub(0,1,0,1),
					f[i][0] + sub(0,0,0,1),
					f[i][1] + sub(0,0,1,1),
					tam[i-1] + sub(0,1,0,0)
				});
				if (layer==1) cot[i] = cot[i] + sub(0,0,1,1); else cot[i] += sub(0,0,0,1);
			}
		}
		for (int i = 1; i <= n; ++i) ans = max({ans , dp[i][0],dp[i][1]});
		cout << ans;
	}
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.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];
 
	if (subtask2::check()){
		subtask2::main_code();
		exit(0);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 604 KB Output is correct
3 Correct 0 ms 348 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 620 KB Output is correct
7 Correct 0 ms 348 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 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 5 ms 616 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 7 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 10 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 604 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 72 ms 604 KB Output is correct
4 Correct 169 ms 604 KB Output is correct
5 Correct 50 ms 604 KB Output is correct
6 Correct 73 ms 684 KB Output is correct
7 Correct 140 ms 744 KB Output is correct
8 Correct 44 ms 600 KB Output is correct
9 Correct 87 ms 704 KB Output is correct
10 Correct 207 ms 600 KB Output is correct
11 Correct 207 ms 600 KB Output is correct
12 Correct 215 ms 848 KB Output is correct
13 Correct 218 ms 600 KB Output is correct
14 Correct 228 ms 732 KB Output is correct
15 Correct 234 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 604 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 72 ms 604 KB Output is correct
4 Correct 169 ms 604 KB Output is correct
5 Correct 50 ms 604 KB Output is correct
6 Correct 73 ms 684 KB Output is correct
7 Correct 140 ms 744 KB Output is correct
8 Correct 44 ms 600 KB Output is correct
9 Correct 87 ms 704 KB Output is correct
10 Correct 207 ms 600 KB Output is correct
11 Correct 207 ms 600 KB Output is correct
12 Correct 215 ms 848 KB Output is correct
13 Correct 218 ms 600 KB Output is correct
14 Correct 228 ms 732 KB Output is correct
15 Correct 234 ms 728 KB Output is correct
16 Correct 109 ms 600 KB Output is correct
17 Correct 133 ms 604 KB Output is correct
18 Correct 118 ms 856 KB Output is correct
19 Correct 24 ms 604 KB Output is correct
20 Correct 84 ms 604 KB Output is correct
21 Correct 5 ms 648 KB Output is correct
22 Correct 27 ms 664 KB Output is correct
23 Correct 52 ms 604 KB Output is correct
24 Correct 19 ms 696 KB Output is correct
25 Correct 223 ms 604 KB Output is correct
26 Correct 212 ms 604 KB Output is correct
27 Correct 210 ms 600 KB Output is correct
28 Correct 212 ms 612 KB Output is correct
29 Correct 229 ms 600 KB Output is correct
30 Correct 232 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 604 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 72 ms 604 KB Output is correct
4 Correct 169 ms 604 KB Output is correct
5 Correct 50 ms 604 KB Output is correct
6 Correct 73 ms 684 KB Output is correct
7 Correct 140 ms 744 KB Output is correct
8 Correct 44 ms 600 KB Output is correct
9 Correct 87 ms 704 KB Output is correct
10 Correct 207 ms 600 KB Output is correct
11 Correct 207 ms 600 KB Output is correct
12 Correct 215 ms 848 KB Output is correct
13 Correct 218 ms 600 KB Output is correct
14 Correct 228 ms 732 KB Output is correct
15 Correct 234 ms 728 KB Output is correct
16 Incorrect 175 ms 604 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 604 KB Output is correct
3 Correct 0 ms 348 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 620 KB Output is correct
7 Correct 0 ms 348 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 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 5 ms 616 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 10 ms 628 KB Output is correct
21 Correct 21 ms 604 KB Output is correct
22 Correct 9 ms 604 KB Output is correct
23 Correct 72 ms 604 KB Output is correct
24 Correct 169 ms 604 KB Output is correct
25 Correct 50 ms 604 KB Output is correct
26 Correct 73 ms 684 KB Output is correct
27 Correct 140 ms 744 KB Output is correct
28 Correct 44 ms 600 KB Output is correct
29 Correct 87 ms 704 KB Output is correct
30 Correct 207 ms 600 KB Output is correct
31 Correct 207 ms 600 KB Output is correct
32 Correct 215 ms 848 KB Output is correct
33 Correct 218 ms 600 KB Output is correct
34 Correct 228 ms 732 KB Output is correct
35 Correct 234 ms 728 KB Output is correct
36 Correct 109 ms 600 KB Output is correct
37 Correct 133 ms 604 KB Output is correct
38 Correct 118 ms 856 KB Output is correct
39 Correct 24 ms 604 KB Output is correct
40 Correct 84 ms 604 KB Output is correct
41 Correct 5 ms 648 KB Output is correct
42 Correct 27 ms 664 KB Output is correct
43 Correct 52 ms 604 KB Output is correct
44 Correct 19 ms 696 KB Output is correct
45 Correct 223 ms 604 KB Output is correct
46 Correct 212 ms 604 KB Output is correct
47 Correct 210 ms 600 KB Output is correct
48 Correct 212 ms 612 KB Output is correct
49 Correct 229 ms 600 KB Output is correct
50 Correct 232 ms 604 KB Output is correct
51 Incorrect 175 ms 604 KB Output isn't correct
52 Halted 0 ms 0 KB -