Submission #679029

# Submission time Handle Problem Language Result Execution time Memory
679029 2023-01-07T08:12:03 Z chv1 Visiting Singapore (NOI20_visitingsingapore) C++14
4 / 100
45 ms 87140 KB
#include<bits/stdc++.h>

using namespace std;

#define int int64_t
int k, n, m, a, b, v[1010], s[5050], t[5050], dp[5050][5050][2][2];

void maximize(int &a, int b) {
    if (a < b) a = b;
}

int32_t main() {
    // freopen("FUNTOUR.inp", "r", stdin);
    // freopen("FUNTOUR.inp", "w", stdout);
    ios::sync_with_stdio(0); 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];
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            dp[i][j][0][0] = max(dp[i][j - 1][0][0], dp[i - 1][j][0][0]) + b;
            dp[i][j][0][1] = dp[i - 1][j][0][1] + b;
            dp[i][j][1][0] = dp[i][j - 1][1][0] + b;
            dp[i][j][1][1] = (j == 1 ? v[t[j]] : v[t[j]] + a);
            if (s[i] == t[j]) {
                maximize(dp[i][j][1][1], dp[i - 1][j - 1][0][0] + 2 * a + v[t[j]]);
                maximize(dp[i][j][1][1], dp[i - 1][j - 1][0][1] + a + v[t[j]]);
                maximize(dp[i][j][1][1], dp[i - 1][j - 1][1][0] + a + v[t[j]]);
                maximize(dp[i][j][1][1], dp[i - 1][j - 1][1][1] + v[t[j]]);
            }
        }
    }
    
    int best = 0;
    for(int i = 0; i <= 1; i++) {
        for(int j = 0; j <= 1; j++) {
            maximize(best, dp[n][m][i][j]);
        }
    }
    
    cout << best;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 15 ms 30804 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 3 ms 4436 KB Output is correct
5 Correct 1 ms 2004 KB Output is correct
6 Correct 5 ms 10836 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 4 ms 4424 KB Output is correct
9 Correct 13 ms 18480 KB Output is correct
10 Correct 22 ms 35780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 87140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 87140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 87140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 15 ms 30804 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 3 ms 4436 KB Output is correct
5 Correct 1 ms 2004 KB Output is correct
6 Correct 5 ms 10836 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 4 ms 4424 KB Output is correct
9 Correct 13 ms 18480 KB Output is correct
10 Correct 22 ms 35780 KB Output is correct
11 Incorrect 1 ms 724 KB Output isn't correct
12 Halted 0 ms 0 KB -