Submission #220696

# Submission time Handle Problem Language Result Execution time Memory
220696 2020-04-08T12:07:35 Z quocnguyen1012 Visiting Singapore (NOI20_visitingsingapore) C++14
4 / 100
18 ms 384 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5e3 + 5, inf = 1e9;

int f[2][maxn][2][2];
int val[maxn], s[maxn], t[maxn], A, B, N, M, K;

int best(int i, int j)
{
  int res;
  if(j) res = A + B * j;
  else res = 0;
  for(int a = 0; a < 2; ++a)
    for(int b = 0; b < 2; ++b)
      res = max(res, f[i][j][a][b]);
  return res;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> K >> N >> M >> A >> B;
  for(int i = 1; i <= K; ++i)
    cin >> val[i];
  for(int i = 1; i <= N; ++i)
    cin >> s[i];
  for(int i = 1; i <= M; ++i)
    cin >> t[i];
  for(int j = 1; j <= M; ++j)
    for(int a = 0; a < 2; ++a)
      for(int b = 0; b < 2; ++b)
        f[0][j][a][b] = -inf;
  int res = A + M * B;
  for(int i = 1, z = 1; z <= N; ++z, i ^= 1){
    for(int a = 0; a < 2; ++a)
      for(int b = 0; b < 2; ++b)
        f[i][0][a][b] = -inf;
    for(int j = 1; j <= M; ++j){
      if(s[z] == t[j]) f[i][j][1][1] = best(i, j - 1) + val[s[z]];
      else f[i][j][1][1] = -inf;
      f[i][j][1][0] = max(f[i][j - 1][1][0] + B, f[i][j - 1][1][1] + A + B);
      f[i][j][0][1] = max(f[i ^ 1][j][0][1] + B, f[i ^ 1][j][1][1] + A + B);
      f[i][j][0][0] = max(f[i][j - 1][0][0] + B, f[i][j - 1][0][1] + A + B);
      f[i][j][0][0] = max(f[i][j][0][0], 2 * A + B * (j + 1));
    }
    res = max(res, best(i, M));
  }
  cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 13 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 13 ms 384 KB Output is correct
11 Incorrect 5 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -