Submission #680200

# Submission time Handle Problem Language Result Execution time Memory
680200 2023-01-10T08:02:49 Z fdnfksd Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
459 ms 196232 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=5005;
const ll inf=1e9;
ll mn2[5005][5005];
ll k,n,m,a,b,s[maxN],v[maxN],t[maxN];
ll dp[5005][5005];
vector<ll> mnhang1,mnhang2;
void update(ll i,ll j,ll val)
{
    mnhang1[j]=max(mnhang1[j-1],val);
    mn2[i][j]=max(mn2[i-1][j],val);
    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    dp[i][j]=max(dp[i][j],val);
}

void solve()
{
    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];
    dp[0][0]=mn2[0][0]=-inf;
    mnhang1.resize(max(m,n)+10);
    mnhang2.resize(max(m,n)+10);
    mnhang2[0]=-inf;
    mnhang1[0]=-inf;
    for(int i=1;i<=max(m,n);i++)
    {
        mnhang2[i]=-inf;
        dp[i][0]=dp[0][i]=mn2[0][i]=mn2[i][0]=-inf;
    }
    ll ans=-inf;
    //mn2 la mncot
    //
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i]==t[j])
            {
                if(i<=1||j<=1) dp[i][j]=-inf;
                dp[i][j]=max(dp[i][j],v[s[i]]+(a*(j>1)+b*(j-1)));
                ll x;
                x=mnhang2[j-1];
                dp[i][j]=max(dp[i][j],x+i*b+j*b-2*b+a+v[s[i]]);
                x=mn2[i-1][j-1];
                dp[i][j]=max(dp[i][j],x+i*b+j*b-2*b+a+v[s[i]]);
                if(i>=2&&j>=2)
                {
                    x=dp[i-2][j-2];
                    dp[i][j]=max(dp[i][j],x+i*b+j*b-2*b+2*a+v[s[i]]);
                }
            }
            else
            {
                dp[i][j]=-inf;
            }
            dp[i+1][j+1]=dp[i][j]+v[s[i+1]];
            ans=max(ans,dp[i][j]+(a*(m>j)+b*(m-j)));
            update(i,j,dp[i][j]-b*i-b*j);
        }
        swap(mnhang1,mnhang2);
    }
    cout << max(ans,a+b*m);
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 17 ms 14548 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 3 ms 7508 KB Output is correct
5 Correct 2 ms 3296 KB Output is correct
6 Correct 7 ms 8360 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 3 ms 4436 KB Output is correct
9 Correct 11 ms 10256 KB Output is correct
10 Correct 21 ms 16160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7508 KB Output is correct
2 Correct 1 ms 3284 KB Output is correct
3 Correct 6 ms 8404 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 11 ms 10332 KB Output is correct
7 Correct 14 ms 11476 KB Output is correct
8 Correct 14 ms 12500 KB Output is correct
9 Correct 3 ms 3540 KB Output is correct
10 Correct 20 ms 16212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 40652 KB Output is correct
2 Correct 19 ms 28244 KB Output is correct
3 Correct 108 ms 95200 KB Output is correct
4 Correct 227 ms 176308 KB Output is correct
5 Correct 83 ms 77608 KB Output is correct
6 Correct 103 ms 94732 KB Output is correct
7 Correct 189 ms 162444 KB Output is correct
8 Correct 72 ms 68940 KB Output is correct
9 Correct 117 ms 107700 KB Output is correct
10 Correct 260 ms 196088 KB Output is correct
11 Correct 263 ms 195560 KB Output is correct
12 Correct 272 ms 196012 KB Output is correct
13 Correct 257 ms 195996 KB Output is correct
14 Correct 430 ms 196088 KB Output is correct
15 Correct 405 ms 196120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 40652 KB Output is correct
2 Correct 19 ms 28244 KB Output is correct
3 Correct 108 ms 95200 KB Output is correct
4 Correct 227 ms 176308 KB Output is correct
5 Correct 83 ms 77608 KB Output is correct
6 Correct 103 ms 94732 KB Output is correct
7 Correct 189 ms 162444 KB Output is correct
8 Correct 72 ms 68940 KB Output is correct
9 Correct 117 ms 107700 KB Output is correct
10 Correct 260 ms 196088 KB Output is correct
11 Correct 263 ms 195560 KB Output is correct
12 Correct 272 ms 196012 KB Output is correct
13 Correct 257 ms 195996 KB Output is correct
14 Correct 430 ms 196088 KB Output is correct
15 Correct 405 ms 196120 KB Output is correct
16 Correct 148 ms 133392 KB Output is correct
17 Correct 184 ms 161688 KB Output is correct
18 Correct 164 ms 148940 KB Output is correct
19 Correct 43 ms 42188 KB Output is correct
20 Correct 116 ms 107912 KB Output is correct
21 Correct 11 ms 15188 KB Output is correct
22 Correct 45 ms 51956 KB Output is correct
23 Correct 78 ms 75696 KB Output is correct
24 Correct 33 ms 40368 KB Output is correct
25 Correct 268 ms 195660 KB Output is correct
26 Correct 312 ms 195680 KB Output is correct
27 Correct 265 ms 196188 KB Output is correct
28 Correct 274 ms 196044 KB Output is correct
29 Correct 402 ms 195568 KB Output is correct
30 Correct 419 ms 195832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 40652 KB Output is correct
2 Correct 19 ms 28244 KB Output is correct
3 Correct 108 ms 95200 KB Output is correct
4 Correct 227 ms 176308 KB Output is correct
5 Correct 83 ms 77608 KB Output is correct
6 Correct 103 ms 94732 KB Output is correct
7 Correct 189 ms 162444 KB Output is correct
8 Correct 72 ms 68940 KB Output is correct
9 Correct 117 ms 107700 KB Output is correct
10 Correct 260 ms 196088 KB Output is correct
11 Correct 263 ms 195560 KB Output is correct
12 Correct 272 ms 196012 KB Output is correct
13 Correct 257 ms 195996 KB Output is correct
14 Correct 430 ms 196088 KB Output is correct
15 Correct 405 ms 196120 KB Output is correct
16 Correct 228 ms 191300 KB Output is correct
17 Correct 122 ms 110728 KB Output is correct
18 Correct 40 ms 42440 KB Output is correct
19 Correct 13 ms 15240 KB Output is correct
20 Correct 11 ms 16340 KB Output is correct
21 Correct 19 ms 37688 KB Output is correct
22 Correct 109 ms 102248 KB Output is correct
23 Correct 27 ms 28736 KB Output is correct
24 Correct 193 ms 171640 KB Output is correct
25 Correct 276 ms 195712 KB Output is correct
26 Correct 260 ms 195816 KB Output is correct
27 Correct 284 ms 195680 KB Output is correct
28 Correct 259 ms 195816 KB Output is correct
29 Correct 403 ms 195768 KB Output is correct
30 Correct 459 ms 196232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 17 ms 14548 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 3 ms 7508 KB Output is correct
5 Correct 2 ms 3296 KB Output is correct
6 Correct 7 ms 8360 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 3 ms 4436 KB Output is correct
9 Correct 11 ms 10256 KB Output is correct
10 Correct 21 ms 16160 KB Output is correct
11 Correct 3 ms 7508 KB Output is correct
12 Correct 1 ms 3284 KB Output is correct
13 Correct 6 ms 8404 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 3 ms 4436 KB Output is correct
16 Correct 11 ms 10332 KB Output is correct
17 Correct 14 ms 11476 KB Output is correct
18 Correct 14 ms 12500 KB Output is correct
19 Correct 3 ms 3540 KB Output is correct
20 Correct 20 ms 16212 KB Output is correct
21 Correct 35 ms 40652 KB Output is correct
22 Correct 19 ms 28244 KB Output is correct
23 Correct 108 ms 95200 KB Output is correct
24 Correct 227 ms 176308 KB Output is correct
25 Correct 83 ms 77608 KB Output is correct
26 Correct 103 ms 94732 KB Output is correct
27 Correct 189 ms 162444 KB Output is correct
28 Correct 72 ms 68940 KB Output is correct
29 Correct 117 ms 107700 KB Output is correct
30 Correct 260 ms 196088 KB Output is correct
31 Correct 263 ms 195560 KB Output is correct
32 Correct 272 ms 196012 KB Output is correct
33 Correct 257 ms 195996 KB Output is correct
34 Correct 430 ms 196088 KB Output is correct
35 Correct 405 ms 196120 KB Output is correct
36 Correct 148 ms 133392 KB Output is correct
37 Correct 184 ms 161688 KB Output is correct
38 Correct 164 ms 148940 KB Output is correct
39 Correct 43 ms 42188 KB Output is correct
40 Correct 116 ms 107912 KB Output is correct
41 Correct 11 ms 15188 KB Output is correct
42 Correct 45 ms 51956 KB Output is correct
43 Correct 78 ms 75696 KB Output is correct
44 Correct 33 ms 40368 KB Output is correct
45 Correct 268 ms 195660 KB Output is correct
46 Correct 312 ms 195680 KB Output is correct
47 Correct 265 ms 196188 KB Output is correct
48 Correct 274 ms 196044 KB Output is correct
49 Correct 402 ms 195568 KB Output is correct
50 Correct 419 ms 195832 KB Output is correct
51 Correct 228 ms 191300 KB Output is correct
52 Correct 122 ms 110728 KB Output is correct
53 Correct 40 ms 42440 KB Output is correct
54 Correct 13 ms 15240 KB Output is correct
55 Correct 11 ms 16340 KB Output is correct
56 Correct 19 ms 37688 KB Output is correct
57 Correct 109 ms 102248 KB Output is correct
58 Correct 27 ms 28736 KB Output is correct
59 Correct 193 ms 171640 KB Output is correct
60 Correct 276 ms 195712 KB Output is correct
61 Correct 260 ms 195816 KB Output is correct
62 Correct 284 ms 195680 KB Output is correct
63 Correct 259 ms 195816 KB Output is correct
64 Correct 403 ms 195768 KB Output is correct
65 Correct 459 ms 196232 KB Output is correct
66 Correct 1 ms 852 KB Output is correct
67 Correct 0 ms 468 KB Output is correct
68 Correct 0 ms 468 KB Output is correct
69 Correct 1 ms 724 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Correct 1 ms 980 KB Output is correct
72 Correct 1 ms 724 KB Output is correct
73 Correct 0 ms 596 KB Output is correct
74 Correct 1 ms 1108 KB Output is correct
75 Correct 1 ms 1108 KB Output is correct
76 Correct 1 ms 1236 KB Output is correct
77 Correct 1 ms 1236 KB Output is correct
78 Correct 1 ms 1108 KB Output is correct
79 Correct 1 ms 1108 KB Output is correct
80 Correct 1 ms 1108 KB Output is correct
81 Correct 222 ms 190508 KB Output is correct
82 Correct 63 ms 59236 KB Output is correct
83 Correct 115 ms 98592 KB Output is correct
84 Correct 59 ms 63948 KB Output is correct
85 Correct 91 ms 84964 KB Output is correct
86 Correct 84 ms 80120 KB Output is correct
87 Correct 19 ms 19648 KB Output is correct
88 Correct 12 ms 15072 KB Output is correct
89 Correct 46 ms 35136 KB Output is correct
90 Correct 299 ms 196004 KB Output is correct
91 Correct 258 ms 195900 KB Output is correct
92 Correct 274 ms 195824 KB Output is correct
93 Correct 257 ms 195908 KB Output is correct
94 Correct 261 ms 195972 KB Output is correct
95 Correct 262 ms 196016 KB Output is correct
96 Correct 261 ms 196048 KB Output is correct
97 Correct 271 ms 196172 KB Output is correct
98 Correct 401 ms 195724 KB Output is correct
99 Correct 412 ms 196060 KB Output is correct
100 Correct 424 ms 195496 KB Output is correct