Submission #832877

# Submission time Handle Problem Language Result Execution time Memory
832877 2023-08-21T16:10:45 Z NK_ Visiting Singapore (NOI20_visitingsingapore) C++17
23 / 100
204 ms 262144 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);

int main() {
	cin.tie(0)->sync_with_stdio(0);
  	
	int K, N, M, A, B; cin >> K >> N >> M >> A >> B;

	vi H(K); for(auto& x : H) cin >> x;
	vi S(N); for(auto& x : S) { cin >> x; --x; }
	vi T(M); for(auto& x : T) { cin >> x; --x; }

	int dp[N+1][2][M+1][2];
	memset(dp, 0xc0, sizeof(dp));

	// can start on any day
	for(int i = 0; i <= N; i++) dp[i][1][0][1] = 0;	

	int ans = -MOD;
	for(int x = 0; x <= N; x++) for(int y = 0; y <= M; y++) {
		for(int ys = 0; ys <= 1; ys++) for(int xs = 0; xs <= 1; xs++) {


			if (y == M) {
				// cerr << x << " " << xs << " " << y << " " << ys << endl;
				// cerr << dp[x][xs][y][ys] << endl;
				ans = max(dp[x][xs][y][ys], ans);
			}

			// go to event
			if (x < N && y < M && S[x] == T[y]) dp[x+1][1][y+1][1] = max(dp[x][xs][y][ys] + H[T[y]], dp[x+1][1][y+1][1]);

			// skip next event in S (x)
			if (x < N) dp[x+1][0][y][ys] = max(dp[x][xs][y][ys] + B + xs * A, dp[x+1][0][y][ys]);

			// skip next event in T (y)
			if (y < M) dp[x][xs][y+1][0] = max(dp[x][xs][y][ys] + B + ys * A, dp[x][xs][y+1][0]);
		}
	}

	cout << ans << nl;

    return 0;	
} 	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 24 ms 13604 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 3924 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 13 ms 7752 KB Output is correct
10 Correct 30 ms 15932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 7 ms 3908 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 1348 KB Output is correct
6 Correct 14 ms 7732 KB Output is correct
7 Correct 15 ms 7764 KB Output is correct
8 Correct 19 ms 11160 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 28 ms 15996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 38100 KB Output is correct
2 Correct 25 ms 15444 KB Output is correct
3 Correct 204 ms 128728 KB Output is correct
4 Runtime error 88 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 38100 KB Output is correct
2 Correct 25 ms 15444 KB Output is correct
3 Correct 204 ms 128728 KB Output is correct
4 Runtime error 88 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 38100 KB Output is correct
2 Correct 25 ms 15444 KB Output is correct
3 Correct 204 ms 128728 KB Output is correct
4 Runtime error 88 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 24 ms 13604 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 3924 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 13 ms 7752 KB Output is correct
10 Correct 30 ms 15932 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 7 ms 3908 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 1348 KB Output is correct
16 Correct 14 ms 7732 KB Output is correct
17 Correct 15 ms 7764 KB Output is correct
18 Correct 19 ms 11160 KB Output is correct
19 Correct 2 ms 1364 KB Output is correct
20 Correct 28 ms 15996 KB Output is correct
21 Correct 60 ms 38100 KB Output is correct
22 Correct 25 ms 15444 KB Output is correct
23 Correct 204 ms 128728 KB Output is correct
24 Runtime error 88 ms 262144 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -