Submission #402970

# Submission time Handle Problem Language Result Execution time Memory
402970 2021-05-12T15:41:53 Z Fidisk Visiting Singapore (NOI20_visitingsingapore) C++14
23 / 100
139 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;

#define oo 1e15
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;

const ll base=361;
const ll mod=998244353;
const ld eps=1e-5;
const ll maxn=1e6;

int k,n,m,a,b,f[5009][5009][2][2],i,j,s[5009],t[5009],v[5009],res;

int main(){
    IO;
    cin>>k>>n>>m>>a>>b;
    for (i=1;i<=k;i++) {
        cin>>v[i];
    }
    for (i=1;i<=n;i++) {
        cin>>s[i];
    }
    for (i=1;i<=m;i++) {
        cin>>t[i];
    }
    for (i=0;i<=n;i++) {
        for (j=0;j<=m;j++) {
            f[i][j][0][0]=-1e9;
            f[i][j][0][1]=-1e9;
            f[i][j][1][0]=-1e9;
        }
    }
    for (i=0;i<=n;i++) {
        f[i][0][0][0]=0;
        for (j=1;j<=m;j++) {
            f[i][j][0][1]=a+j*b;
        }
    }
    res=-1e9;
    for (i=1;i<=n;i++) {
        for (j=1;j<=m;j++) {
            f[i][j][0][0]=max({f[i-1][j][0][1]+a,f[i-1][j][0][0],f[i-1][j][1][0]+a})+b;
            f[i][j][0][1]=max({f[i][j-1][1][0]+a,f[i][j-1][0][0]+a,f[i][j-1][0][1]})+b;
            if (s[i]==t[j]) {
                f[i][j][1][0]=max({f[i-1][j-1][0][0],f[i-1][j-1][0][1],f[i-1][j-1][1][0]})+v[s[i]];
            }
        }
    }
    for (i=1;i<=n;i++) {
        res=max({res,f[i][m][0][0],f[i][m][1][0],f[i][m][0][1]});
    }
    /*
    for (i=1;i<=n;i++) {
        for (j=1;j<=m;j++) {
            cout<<f[i][j][0][0]<<' ';
        }
        cout<<'\n';
    }
    cout<<'\n';
    for (i=1;i<=n;i++) {
        for (j=1;j<=m;j++) {
            cout<<f[i][j][0][1]<<' ';
        }
        cout<<'\n';
    }
    cout<<'\n';
    for (i=1;i<=n;i++) {
        for (j=1;j<=m;j++) {
            cout<<f[i][j][1][0]<<' ';
        }
        cout<<'\n';
    }
    */
    cout<<res<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 16 ms 17484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 3 ms 4044 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 6 ms 7116 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 3 ms 3276 KB Output is correct
9 Correct 10 ms 10964 KB Output is correct
10 Correct 19 ms 20028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 5 ms 5196 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 2 ms 1996 KB Output is correct
6 Correct 9 ms 10188 KB Output is correct
7 Correct 9 ms 9888 KB Output is correct
8 Correct 13 ms 14396 KB Output is correct
9 Correct 2 ms 2380 KB Output is correct
10 Correct 19 ms 20104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 49056 KB Output is correct
2 Correct 21 ms 25804 KB Output is correct
3 Correct 131 ms 144268 KB Output is correct
4 Runtime error 139 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 49056 KB Output is correct
2 Correct 21 ms 25804 KB Output is correct
3 Correct 131 ms 144268 KB Output is correct
4 Runtime error 139 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 49056 KB Output is correct
2 Correct 21 ms 25804 KB Output is correct
3 Correct 131 ms 144268 KB Output is correct
4 Runtime error 139 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 844 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 16 ms 17484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 3 ms 4044 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 6 ms 7116 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 3 ms 3276 KB Output is correct
9 Correct 10 ms 10964 KB Output is correct
10 Correct 19 ms 20028 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 5 ms 5196 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 2 ms 1996 KB Output is correct
16 Correct 9 ms 10188 KB Output is correct
17 Correct 9 ms 9888 KB Output is correct
18 Correct 13 ms 14396 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 19 ms 20104 KB Output is correct
21 Correct 42 ms 49056 KB Output is correct
22 Correct 21 ms 25804 KB Output is correct
23 Correct 131 ms 144268 KB Output is correct
24 Runtime error 139 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -