Submission #490882

# Submission time Handle Problem Language Result Execution time Memory
490882 2021-11-29T15:50:45 Z KienTran Visiting Singapore (NOI20_visitingsingapore) C++14
23 / 100
180 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;

    dp[0][0] = -inf;
    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]];
        }

        dp[i][0] = -inf;
        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 1 ms 3148 KB Output is correct
2 Correct 14 ms 21708 KB Output is correct
3 Correct 1 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 7 ms 12364 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 3 ms 6476 KB Output is correct
9 Correct 10 ms 15308 KB Output is correct
10 Correct 16 ms 24160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 5 ms 6604 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 9 ms 13232 KB Output is correct
7 Correct 10 ms 12108 KB Output is correct
8 Correct 13 ms 18168 KB Output is correct
9 Correct 2 ms 3916 KB Output is correct
10 Correct 17 ms 24080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 60676 KB Output is correct
2 Correct 22 ms 42156 KB Output is correct
3 Correct 110 ms 142424 KB Output is correct
4 Runtime error 180 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 60676 KB Output is correct
2 Correct 22 ms 42156 KB Output is correct
3 Correct 110 ms 142424 KB Output is correct
4 Runtime error 180 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 60676 KB Output is correct
2 Correct 22 ms 42156 KB Output is correct
3 Correct 110 ms 142424 KB Output is correct
4 Runtime error 180 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 1 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 1220 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 2 ms 1612 KB Output is correct
15 Correct 1 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3148 KB Output is correct
2 Correct 14 ms 21708 KB Output is correct
3 Correct 1 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 7 ms 12364 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 3 ms 6476 KB Output is correct
9 Correct 10 ms 15308 KB Output is correct
10 Correct 16 ms 24160 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 5 ms 6604 KB Output is correct
14 Correct 1 ms 1204 KB Output is correct
15 Correct 2 ms 3020 KB Output is correct
16 Correct 9 ms 13232 KB Output is correct
17 Correct 10 ms 12108 KB Output is correct
18 Correct 13 ms 18168 KB Output is correct
19 Correct 2 ms 3916 KB Output is correct
20 Correct 17 ms 24080 KB Output is correct
21 Correct 44 ms 60676 KB Output is correct
22 Correct 22 ms 42156 KB Output is correct
23 Correct 110 ms 142424 KB Output is correct
24 Runtime error 180 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -