# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209418 | 2020-03-14T07:23:25 Z | model_code | Visiting Singapore (NOI20_visitingsingapore) | C++17 | 217 ms | 808 KB |
#include<bits/stdc++.h> using namespace std; typedef long long int ll; ll val[1005]; ll arr[5005],arr2[5005]; ll dp[2][5005][4],ans; int main(){ ios::sync_with_stdio(0); cin.tie(0); ll x,y,z,n,m,a,b,c,d,i,j,k; cin>>k>>n>>m>>x>>y; x = -x; y = -y; ans = -x-y*m; for(i=0;i<k;i++)cin>>val[i+1]; for(i=1;i<=n;i++)cin>>arr[i]; for(i=1;i<=m;i++)cin>>arr2[i]; for(i=1;i<=m;i++){ dp[0][i][0] = -2e9; dp[0][i][1] = -2e9; dp[0][i][3] = -2e9; dp[0][i][2] = -x-y*i; } dp[0][0][0] = -2e9; dp[0][0][1] = -2e9; dp[0][0][2] = -2e9; dp[0][0][3] = 0; dp[1][0][0] = -2e9; dp[1][0][1] = -2e9; dp[1][0][2] = -2e9; dp[1][0][3] = 0; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ dp[i%2][j][0] = max({-x-y*j,max(dp[i%2][j-1][0],dp[(i-1)%2][j][0])-y,max(dp[(i-1)%2][j][2],dp[i%2][j-1][1])-x-y}); dp[i%2][j][1] = max({dp[(i-1)%2][j][1]-y,dp[(i-1)%2][j][3]-x-y}); dp[i%2][j][2] = max({dp[i%2][j-1][2]-y,dp[i%2][j-1][3]-x-y,-x-y*j}); if(arr[i]==arr2[j]){ dp[i%2][j][3] = val[arr[i]]+max({dp[(i-1)%2][j-1][0],dp[(i-1)%2][j-1][1],dp[(i-1)%2][j-1][2],dp[(i-1)%2][j-1][3]}); }else dp[i%2][j][3] = -2e9; // cout<<i<<" "<<j<<" states: \n"; // for(k=0;k<4;k++)cout<<dp[i][j][k]<<" "<<k/2<<k%2<<'\n'; } for(j=0;j<4;j++)ans = max(ans,dp[i%2][m][j]); } cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 11 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 8 ms | 376 KB | Output is correct |
10 | Correct | 13 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 7 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 8 ms | 376 KB | Output is correct |
7 | Correct | 9 ms | 504 KB | Output is correct |
8 | Correct | 10 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 13 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 376 KB | Output is correct |
2 | Correct | 11 ms | 376 KB | Output is correct |
3 | Correct | 60 ms | 504 KB | Output is correct |
4 | Correct | 149 ms | 760 KB | Output is correct |
5 | Correct | 46 ms | 632 KB | Output is correct |
6 | Correct | 63 ms | 632 KB | Output is correct |
7 | Correct | 114 ms | 632 KB | Output is correct |
8 | Correct | 40 ms | 504 KB | Output is correct |
9 | Correct | 74 ms | 632 KB | Output is correct |
10 | Correct | 187 ms | 760 KB | Output is correct |
11 | Correct | 176 ms | 760 KB | Output is correct |
12 | Correct | 175 ms | 760 KB | Output is correct |
13 | Correct | 177 ms | 760 KB | Output is correct |
14 | Correct | 206 ms | 788 KB | Output is correct |
15 | Correct | 217 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 376 KB | Output is correct |
2 | Correct | 11 ms | 376 KB | Output is correct |
3 | Correct | 60 ms | 504 KB | Output is correct |
4 | Correct | 149 ms | 760 KB | Output is correct |
5 | Correct | 46 ms | 632 KB | Output is correct |
6 | Correct | 63 ms | 632 KB | Output is correct |
7 | Correct | 114 ms | 632 KB | Output is correct |
8 | Correct | 40 ms | 504 KB | Output is correct |
9 | Correct | 74 ms | 632 KB | Output is correct |
10 | Correct | 187 ms | 760 KB | Output is correct |
11 | Correct | 176 ms | 760 KB | Output is correct |
12 | Correct | 175 ms | 760 KB | Output is correct |
13 | Correct | 177 ms | 760 KB | Output is correct |
14 | Correct | 206 ms | 788 KB | Output is correct |
15 | Correct | 217 ms | 760 KB | Output is correct |
16 | Correct | 94 ms | 632 KB | Output is correct |
17 | Correct | 115 ms | 632 KB | Output is correct |
18 | Correct | 113 ms | 648 KB | Output is correct |
19 | Correct | 25 ms | 632 KB | Output is correct |
20 | Correct | 78 ms | 620 KB | Output is correct |
21 | Correct | 10 ms | 376 KB | Output is correct |
22 | Correct | 27 ms | 636 KB | Output is correct |
23 | Correct | 48 ms | 632 KB | Output is correct |
24 | Correct | 20 ms | 376 KB | Output is correct |
25 | Correct | 176 ms | 808 KB | Output is correct |
26 | Correct | 182 ms | 760 KB | Output is correct |
27 | Correct | 180 ms | 760 KB | Output is correct |
28 | Correct | 184 ms | 784 KB | Output is correct |
29 | Correct | 203 ms | 780 KB | Output is correct |
30 | Correct | 202 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 376 KB | Output is correct |
2 | Correct | 11 ms | 376 KB | Output is correct |
3 | Correct | 60 ms | 504 KB | Output is correct |
4 | Correct | 149 ms | 760 KB | Output is correct |
5 | Correct | 46 ms | 632 KB | Output is correct |
6 | Correct | 63 ms | 632 KB | Output is correct |
7 | Correct | 114 ms | 632 KB | Output is correct |
8 | Correct | 40 ms | 504 KB | Output is correct |
9 | Correct | 74 ms | 632 KB | Output is correct |
10 | Correct | 187 ms | 760 KB | Output is correct |
11 | Correct | 176 ms | 760 KB | Output is correct |
12 | Correct | 175 ms | 760 KB | Output is correct |
13 | Correct | 177 ms | 760 KB | Output is correct |
14 | Correct | 206 ms | 788 KB | Output is correct |
15 | Correct | 217 ms | 760 KB | Output is correct |
16 | Correct | 156 ms | 748 KB | Output is correct |
17 | Correct | 72 ms | 504 KB | Output is correct |
18 | Correct | 27 ms | 504 KB | Output is correct |
19 | Correct | 10 ms | 468 KB | Output is correct |
20 | Correct | 8 ms | 504 KB | Output is correct |
21 | Correct | 9 ms | 632 KB | Output is correct |
22 | Correct | 70 ms | 636 KB | Output is correct |
23 | Correct | 21 ms | 376 KB | Output is correct |
24 | Correct | 119 ms | 632 KB | Output is correct |
25 | Correct | 187 ms | 784 KB | Output is correct |
26 | Correct | 177 ms | 776 KB | Output is correct |
27 | Correct | 178 ms | 760 KB | Output is correct |
28 | Correct | 180 ms | 664 KB | Output is correct |
29 | Correct | 207 ms | 760 KB | Output is correct |
30 | Correct | 203 ms | 784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 4 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 11 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 8 ms | 376 KB | Output is correct |
10 | Correct | 13 ms | 380 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 7 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 8 ms | 376 KB | Output is correct |
17 | Correct | 9 ms | 504 KB | Output is correct |
18 | Correct | 10 ms | 376 KB | Output is correct |
19 | Correct | 5 ms | 376 KB | Output is correct |
20 | Correct | 13 ms | 376 KB | Output is correct |
21 | Correct | 21 ms | 376 KB | Output is correct |
22 | Correct | 11 ms | 376 KB | Output is correct |
23 | Correct | 60 ms | 504 KB | Output is correct |
24 | Correct | 149 ms | 760 KB | Output is correct |
25 | Correct | 46 ms | 632 KB | Output is correct |
26 | Correct | 63 ms | 632 KB | Output is correct |
27 | Correct | 114 ms | 632 KB | Output is correct |
28 | Correct | 40 ms | 504 KB | Output is correct |
29 | Correct | 74 ms | 632 KB | Output is correct |
30 | Correct | 187 ms | 760 KB | Output is correct |
31 | Correct | 176 ms | 760 KB | Output is correct |
32 | Correct | 175 ms | 760 KB | Output is correct |
33 | Correct | 177 ms | 760 KB | Output is correct |
34 | Correct | 206 ms | 788 KB | Output is correct |
35 | Correct | 217 ms | 760 KB | Output is correct |
36 | Correct | 94 ms | 632 KB | Output is correct |
37 | Correct | 115 ms | 632 KB | Output is correct |
38 | Correct | 113 ms | 648 KB | Output is correct |
39 | Correct | 25 ms | 632 KB | Output is correct |
40 | Correct | 78 ms | 620 KB | Output is correct |
41 | Correct | 10 ms | 376 KB | Output is correct |
42 | Correct | 27 ms | 636 KB | Output is correct |
43 | Correct | 48 ms | 632 KB | Output is correct |
44 | Correct | 20 ms | 376 KB | Output is correct |
45 | Correct | 176 ms | 808 KB | Output is correct |
46 | Correct | 182 ms | 760 KB | Output is correct |
47 | Correct | 180 ms | 760 KB | Output is correct |
48 | Correct | 184 ms | 784 KB | Output is correct |
49 | Correct | 203 ms | 780 KB | Output is correct |
50 | Correct | 202 ms | 760 KB | Output is correct |
51 | Correct | 156 ms | 748 KB | Output is correct |
52 | Correct | 72 ms | 504 KB | Output is correct |
53 | Correct | 27 ms | 504 KB | Output is correct |
54 | Correct | 10 ms | 468 KB | Output is correct |
55 | Correct | 8 ms | 504 KB | Output is correct |
56 | Correct | 9 ms | 632 KB | Output is correct |
57 | Correct | 70 ms | 636 KB | Output is correct |
58 | Correct | 21 ms | 376 KB | Output is correct |
59 | Correct | 119 ms | 632 KB | Output is correct |
60 | Correct | 187 ms | 784 KB | Output is correct |
61 | Correct | 177 ms | 776 KB | Output is correct |
62 | Correct | 178 ms | 760 KB | Output is correct |
63 | Correct | 180 ms | 664 KB | Output is correct |
64 | Correct | 207 ms | 760 KB | Output is correct |
65 | Correct | 203 ms | 784 KB | Output is correct |
66 | Correct | 5 ms | 376 KB | Output is correct |
67 | Correct | 5 ms | 376 KB | Output is correct |
68 | Correct | 4 ms | 376 KB | Output is correct |
69 | Correct | 5 ms | 376 KB | Output is correct |
70 | Correct | 5 ms | 376 KB | Output is correct |
71 | Correct | 5 ms | 376 KB | Output is correct |
72 | Correct | 5 ms | 376 KB | Output is correct |
73 | Correct | 5 ms | 376 KB | Output is correct |
74 | Correct | 5 ms | 376 KB | Output is correct |
75 | Correct | 5 ms | 376 KB | Output is correct |
76 | Correct | 5 ms | 376 KB | Output is correct |
77 | Correct | 5 ms | 376 KB | Output is correct |
78 | Correct | 5 ms | 376 KB | Output is correct |
79 | Correct | 5 ms | 376 KB | Output is correct |
80 | Correct | 5 ms | 376 KB | Output is correct |
81 | Correct | 148 ms | 632 KB | Output is correct |
82 | Correct | 36 ms | 504 KB | Output is correct |
83 | Correct | 69 ms | 636 KB | Output is correct |
84 | Correct | 37 ms | 632 KB | Output is correct |
85 | Correct | 62 ms | 632 KB | Output is correct |
86 | Correct | 51 ms | 504 KB | Output is correct |
87 | Correct | 12 ms | 504 KB | Output is correct |
88 | Correct | 10 ms | 376 KB | Output is correct |
89 | Correct | 26 ms | 504 KB | Output is correct |
90 | Correct | 194 ms | 760 KB | Output is correct |
91 | Correct | 177 ms | 764 KB | Output is correct |
92 | Correct | 179 ms | 760 KB | Output is correct |
93 | Correct | 188 ms | 760 KB | Output is correct |
94 | Correct | 186 ms | 760 KB | Output is correct |
95 | Correct | 182 ms | 760 KB | Output is correct |
96 | Correct | 181 ms | 776 KB | Output is correct |
97 | Correct | 182 ms | 760 KB | Output is correct |
98 | Correct | 210 ms | 760 KB | Output is correct |
99 | Correct | 205 ms | 760 KB | Output is correct |
100 | Correct | 204 ms | 780 KB | Output is correct |