Submission #439031

# Submission time Handle Problem Language Result Execution time Memory
439031 2021-06-29T05:49:07 Z meatrow Visiting Singapore (NOI20_visitingsingapore) C++17
4 / 100
423 ms 508 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
const int MOD = 998244353;
 
ll binpow(ll a, ll p, int mod = MOD) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            (res *= a) %= mod;
        }
        p >>= 1;
        (a *= a) %= mod;
    }
    return res;
}
 
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

const int INF = -1e9;
using state = array<array<int, 2>, 2>;
const state INIT = state{array<int, 2>{INF, INF}, array<int, 2>{INF, INF}};

void solve() {
    int K, n, m;
    int A, B;
    cin >> K >> n >> m >> A >> B;
    vector<int> v(K + 1);
    for (int i = 1; i <= K; i++) {
        cin >> v[i];
    }
    vector<int> s(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
    }
    vector<int> t(n + 1);
    for (int i = 1; i <= m; i++) {
        cin >> t[i];
    }
    auto chmax = [&](int& cur, int val) {
        if (val < INF / 2) return;
        cur = max(cur, val);
    };

    int ans = A + B * m;
    vector<state> dp(m + 1, INIT);
    for (int i = 1; i <= n; i++) {
        vector<state> nxt(m + 1, INIT);
        for (int j = 0; j <= m; j++) {
            if (j && s[i] == t[j]) {
                chmax(nxt[j][1][1], v[s[i]] + A * (j > 1) + B * (j - 1));
            }
            for (int f = 0; f < 2; f++) {
                for (int g = 0; g < 2; g++) {
                    chmax(nxt[j][0][g], dp[j][f][g] + A * f + B);
                    if (j) chmax(nxt[j][f][0], nxt[j - 1][f][g] + A * g + B);
                    if (j && s[i] == t[j]) {
                        chmax(nxt[j][1][1], dp[j - 1][f][g] + v[s[i]]);
                    }
                }
            }
            for (int f = 0; f < 2; f++) {
                for (int g = 0; g < 2; g++) {
                    chmax(ans, nxt[j][f][g] + A * (m - j > 0) + B * (m - j));
                }
            }
        }
        dp = move(nxt);
    }
    cout << ans << endl;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    for (int tc = 1; tc <= T; tc++) {
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 24 ms 352 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 7 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 312 KB Output is correct
9 Correct 14 ms 332 KB Output is correct
10 Correct 29 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 332 KB Output is correct
2 Correct 23 ms 332 KB Output is correct
3 Correct 180 ms 332 KB Output is correct
4 Correct 423 ms 508 KB Output is correct
5 Runtime error 1 ms 464 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 332 KB Output is correct
2 Correct 23 ms 332 KB Output is correct
3 Correct 180 ms 332 KB Output is correct
4 Correct 423 ms 508 KB Output is correct
5 Runtime error 1 ms 464 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 332 KB Output is correct
2 Correct 23 ms 332 KB Output is correct
3 Correct 180 ms 332 KB Output is correct
4 Correct 423 ms 508 KB Output is correct
5 Runtime error 1 ms 464 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 464 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 24 ms 352 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 7 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 312 KB Output is correct
9 Correct 14 ms 332 KB Output is correct
10 Correct 29 ms 332 KB Output is correct
11 Runtime error 1 ms 460 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -