Submission #669738

# Submission time Handle Problem Language Result Execution time Memory
669738 2022-12-07T07:50:13 Z omkarbajaj073 Visiting Singapore (NOI20_visitingsingapore) C++17
29 / 100
245 ms 196252 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5005, MAX_K = 1005;
const int inf = 1e9;

int K, N, M, V[MAX_K], S[MAX_N], T[MAX_N], a, b, dp[MAX_N][MAX_N][2];

int main() {
  
  ios_base::sync_with_stdio(false); cin.tie(0);

  cin >> K >> N >> M >> a >> b;
  for (int i = 0; i < K; i++) cin >> V[i];
  for (int i = 1; i <= N; i++) {
    cin >> S[i]; S[i]--;
  }
  for (int i = 1; i <= M; i++) {
    cin >> T[i]; T[i]--;
  }

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      dp[i][j][0] = dp[i][j][1] = -inf;
    }
  }

  for (int j = 0; j <= M; j++) 
    dp[0][j][0] = a + j * b;

  for (int i = 0; i <= N; i++) 
    dp[i][0][0] = 0;
  
  

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      // skipping a day
      if (i != 1)
        dp[i][j][0] = max(dp[i-1][j][0] + b, dp[i-1][j][1] + a + b);
      else 
        dp[i][j][0] = max(dp[i-1][j][0] + a + b, dp[i-1][j][1] + a + b);

      if (j != 1)
        dp[i][j][0] = max(dp[i][j][0], max(dp[i][j-1][1] + a + b, dp[i][j-1][0] + b));
      else 
        dp[i][j][0] = max(dp[i][j][0], max(dp[i][j-1][1] + a + b, dp[i][j-1][0] + a + b));

      if (S[i] == T[j]) {
        int tmp = (j == 1) ? 0 : ((j-1) * b + a);
        dp[i][j][1] = max(max(dp[i-1][j-1][0], dp[i-1][j-1][1]), tmp) + V[S[i]];
      }

      // cout << i << ", " << j << " dp: " << dp[i][j][0] << ", " << dp[i][j][1] << endl;
    }
  }

  int ans = a + M * b;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (j == M) ans = max(ans, max(dp[i][j][0], dp[i][j][1]));
      else ans = max(ans, max(dp[i][j][0] + (M-j) * b, dp[i][j][1]  + a + (M-j)*b));
    }
  }

  cout << ans << endl;

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 11 ms 10840 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 2 ms 3924 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 7 ms 7124 KB Output is correct
10 Correct 12 ms 12244 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 3 ms 3280 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 6 ms 6476 KB Output is correct
7 Correct 7 ms 6088 KB Output is correct
8 Correct 9 ms 9044 KB Output is correct
9 Correct 1 ms 1748 KB Output is correct
10 Correct 14 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 29916 KB Output is correct
2 Correct 14 ms 18132 KB Output is correct
3 Correct 83 ms 79928 KB Output is correct
4 Correct 197 ms 174284 KB Output is correct
5 Correct 57 ms 51420 KB Output is correct
6 Correct 84 ms 76220 KB Output is correct
7 Correct 152 ms 143432 KB Output is correct
8 Correct 55 ms 54888 KB Output is correct
9 Correct 115 ms 91432 KB Output is correct
10 Correct 227 ms 196048 KB Output is correct
11 Correct 227 ms 195472 KB Output is correct
12 Correct 245 ms 196044 KB Output is correct
13 Correct 226 ms 196028 KB Output is correct
14 Correct 242 ms 196044 KB Output is correct
15 Correct 243 ms 196024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 29916 KB Output is correct
2 Correct 14 ms 18132 KB Output is correct
3 Correct 83 ms 79928 KB Output is correct
4 Correct 197 ms 174284 KB Output is correct
5 Correct 57 ms 51420 KB Output is correct
6 Correct 84 ms 76220 KB Output is correct
7 Correct 152 ms 143432 KB Output is correct
8 Correct 55 ms 54888 KB Output is correct
9 Correct 115 ms 91432 KB Output is correct
10 Correct 227 ms 196048 KB Output is correct
11 Correct 227 ms 195472 KB Output is correct
12 Correct 245 ms 196044 KB Output is correct
13 Correct 226 ms 196028 KB Output is correct
14 Correct 242 ms 196044 KB Output is correct
15 Correct 243 ms 196024 KB Output is correct
16 Correct 127 ms 117748 KB Output is correct
17 Correct 154 ms 142448 KB Output is correct
18 Correct 149 ms 129228 KB Output is correct
19 Correct 30 ms 26836 KB Output is correct
20 Correct 98 ms 92888 KB Output is correct
21 Correct 8 ms 9940 KB Output is correct
22 Correct 33 ms 28860 KB Output is correct
23 Correct 62 ms 56924 KB Output is correct
24 Correct 26 ms 29012 KB Output is correct
25 Correct 243 ms 195444 KB Output is correct
26 Correct 229 ms 195648 KB Output is correct
27 Correct 227 ms 196252 KB Output is correct
28 Correct 231 ms 196136 KB Output is correct
29 Correct 240 ms 195556 KB Output is correct
30 Correct 237 ms 195788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 29916 KB Output is correct
2 Correct 14 ms 18132 KB Output is correct
3 Correct 83 ms 79928 KB Output is correct
4 Correct 197 ms 174284 KB Output is correct
5 Correct 57 ms 51420 KB Output is correct
6 Correct 84 ms 76220 KB Output is correct
7 Correct 152 ms 143432 KB Output is correct
8 Correct 55 ms 54888 KB Output is correct
9 Correct 115 ms 91432 KB Output is correct
10 Correct 227 ms 196048 KB Output is correct
11 Correct 227 ms 195472 KB Output is correct
12 Correct 245 ms 196044 KB Output is correct
13 Correct 226 ms 196028 KB Output is correct
14 Correct 242 ms 196044 KB Output is correct
15 Correct 243 ms 196024 KB Output is correct
16 Incorrect 202 ms 182424 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 11 ms 10840 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 2 ms 3924 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 7 ms 7124 KB Output is correct
10 Correct 12 ms 12244 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 3 ms 3280 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 6 ms 6476 KB Output is correct
17 Correct 7 ms 6088 KB Output is correct
18 Correct 9 ms 9044 KB Output is correct
19 Correct 1 ms 1748 KB Output is correct
20 Correct 14 ms 12244 KB Output is correct
21 Correct 27 ms 29916 KB Output is correct
22 Correct 14 ms 18132 KB Output is correct
23 Correct 83 ms 79928 KB Output is correct
24 Correct 197 ms 174284 KB Output is correct
25 Correct 57 ms 51420 KB Output is correct
26 Correct 84 ms 76220 KB Output is correct
27 Correct 152 ms 143432 KB Output is correct
28 Correct 55 ms 54888 KB Output is correct
29 Correct 115 ms 91432 KB Output is correct
30 Correct 227 ms 196048 KB Output is correct
31 Correct 227 ms 195472 KB Output is correct
32 Correct 245 ms 196044 KB Output is correct
33 Correct 226 ms 196028 KB Output is correct
34 Correct 242 ms 196044 KB Output is correct
35 Correct 243 ms 196024 KB Output is correct
36 Correct 127 ms 117748 KB Output is correct
37 Correct 154 ms 142448 KB Output is correct
38 Correct 149 ms 129228 KB Output is correct
39 Correct 30 ms 26836 KB Output is correct
40 Correct 98 ms 92888 KB Output is correct
41 Correct 8 ms 9940 KB Output is correct
42 Correct 33 ms 28860 KB Output is correct
43 Correct 62 ms 56924 KB Output is correct
44 Correct 26 ms 29012 KB Output is correct
45 Correct 243 ms 195444 KB Output is correct
46 Correct 229 ms 195648 KB Output is correct
47 Correct 227 ms 196252 KB Output is correct
48 Correct 231 ms 196136 KB Output is correct
49 Correct 240 ms 195556 KB Output is correct
50 Correct 237 ms 195788 KB Output is correct
51 Incorrect 202 ms 182424 KB Output isn't correct
52 Halted 0 ms 0 KB -