Submission #490883

# Submission time Handle Problem Language Result Execution time Memory
490883 2021-11-29T15:53:04 Z KienTran Visiting Singapore (NOI20_visitingsingapore) C++14
23 / 100
225 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

const int O = 5e3 + 5;
const int inf = 1e9;

int k, n, m, a, b, v[O], s[O], t[O], f[2][O][O], dp[O][O];

main(){
    ios_base::sync_with_stdio(false); 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 = 0; i <= n; ++ i){
        for (int j = 1; j <= m; ++ j){
            f[0][i][j] = -inf;
            f[1][i][j] = -inf;
        }
    }
    for (int j = 0; j <= m; ++ j) dp[0][j] = b * j;

    f[0][0][0] = f[1][0][0] = 0;
    for (int i = 1; i <= n; ++ i){
        for (int j = 1; j <= m; ++ j){
            f[0][i][j] = max(f[0][i - 1][j] + b, f[1][i - 1][j] + a + b);
            if (s[i] == t[j]) f[1][i][j] = max({dp[i - 1][j - 1] + a, f[0][i - 1][j - 1], f[1][i - 1][j - 1]}) + v[s[i]];
        }

        for (int j = 1; j <= m; ++ j)
            dp[i][j] = max({dp[i][j - 1], f[1][i][j - 1], f[0][i][j - 1]}) + b;
    }

    int res = a + b * m;
    for (int i = 0; i <= n; ++ i){
        for (int j = 0; j <= m; ++ j){
            int cost = max(f[0][i][j], f[1][i][j]) + a + b * (m - j);
            if (j == m) cost -= a;
            res = max(res, cost);
        }
    }

    cout << res;
}

Compilation message

VisitingSingapore.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3148 KB Output is correct
2 Correct 17 ms 21748 KB Output is correct
3 Correct 2 ms 3276 KB Output is correct
4 Correct 5 ms 10956 KB Output is correct
5 Correct 2 ms 4812 KB Output is correct
6 Correct 9 ms 12392 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 6476 KB Output is correct
9 Correct 11 ms 15180 KB Output is correct
10 Correct 20 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 5 ms 6608 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 11 ms 13132 KB Output is correct
7 Correct 9 ms 12132 KB Output is correct
8 Correct 15 ms 18172 KB Output is correct
9 Correct 2 ms 3916 KB Output is correct
10 Correct 20 ms 24140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 60748 KB Output is correct
2 Correct 26 ms 42188 KB Output is correct
3 Correct 123 ms 142476 KB Output is correct
4 Runtime error 225 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 60748 KB Output is correct
2 Correct 26 ms 42188 KB Output is correct
3 Correct 123 ms 142476 KB Output is correct
4 Runtime error 225 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 60748 KB Output is correct
2 Correct 26 ms 42188 KB Output is correct
3 Correct 123 ms 142476 KB Output is correct
4 Runtime error 225 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1612 KB Output is correct
11 Correct 1 ms 1612 KB Output is correct
12 Correct 1 ms 1612 KB Output is correct
13 Correct 1 ms 1612 KB Output is correct
14 Correct 1 ms 1612 KB Output is correct
15 Correct 1 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3148 KB Output is correct
2 Correct 17 ms 21748 KB Output is correct
3 Correct 2 ms 3276 KB Output is correct
4 Correct 5 ms 10956 KB Output is correct
5 Correct 2 ms 4812 KB Output is correct
6 Correct 9 ms 12392 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 6476 KB Output is correct
9 Correct 11 ms 15180 KB Output is correct
10 Correct 20 ms 24172 KB Output is correct
11 Correct 0 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 5 ms 6608 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 2 ms 3020 KB Output is correct
16 Correct 11 ms 13132 KB Output is correct
17 Correct 9 ms 12132 KB Output is correct
18 Correct 15 ms 18172 KB Output is correct
19 Correct 2 ms 3916 KB Output is correct
20 Correct 20 ms 24140 KB Output is correct
21 Correct 44 ms 60748 KB Output is correct
22 Correct 26 ms 42188 KB Output is correct
23 Correct 123 ms 142476 KB Output is correct
24 Runtime error 225 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -