Submission #298299

# Submission time Handle Problem Language Result Execution time Memory
298299 2020-09-12T17:02:16 Z beso123 Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
352 ms 900 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define inf -3e9
using namespace std;
const int N=6006;
int n,m,q,a,b;
int dp[N][4],h[N],s[N],t[N],f[N][4];
main(){
cin>>q>>n>>m>>a>>b;
for(int k=1;k<=q;k++)
    cin>>h[k];
for(int k=1;k<=n;k++)
    cin>>s[k];
for(int k=1;k<=m;k++)
    cin>>t[k];
    int ans=a+b*m;
for(int k=0;k<=m;k++){
    f[k][0]=inf;
     f[k][1]=inf;
      f[k][2]=inf;
       f[k][3]=inf;
}
dp[0][0]=inf;
dp[0][1]=inf;
dp[0][2]=inf;
dp[0][3]=inf;
for(int k=1;k<=n;k++){
    for(int i=1;i<=m;i++){
        dp[i][0]=max(dp[i-1][0],f[i][0])+b;
        dp[i][1]=f[i][1]+b;
        dp[i][2]=dp[i-1][2]+b;
        if(s[k]==t[i]){
        dp[i][3]=h[t[i]];
        if(i!=1)
            dp[i][3]+=a+(i-1)*b;
        dp[i][3]=max(dp[i][3],
                        max(f[i-1][0]+(2*a)+h[t[i]],
                            max(f[i-1][1]+a+h[t[i]],
                                max(f[i-1][2]+a+h[t[i]],f[i-1][3]+h[t[i]]))));
        dp[i][0]=max(dp[i][0],dp[i][3]);
        dp[i][1]=max(dp[i][1],dp[i][3]);
        dp[i][2]=max(dp[i][2],dp[i][3]);
        int pas=dp[i][3]+b*(m-i);
        if(i!=m)
            pas+=a;
        ans=max(ans,pas);
        }
        else dp[i][3]=inf;
    }
    for(int q=1;q<=m;q++){
            for(int i=0;i<=3;i++){
        f[q][i]=dp[q][i];
        dp[q][i]=0;
            }
    }
}
cout<<ans;
return 0;
}

Compilation message

VisitingSingapore.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 14 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 11 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 18 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 384 KB Output is correct
2 Correct 11 ms 384 KB Output is correct
3 Correct 73 ms 512 KB Output is correct
4 Correct 179 ms 768 KB Output is correct
5 Correct 57 ms 640 KB Output is correct
6 Correct 86 ms 764 KB Output is correct
7 Correct 154 ms 640 KB Output is correct
8 Correct 48 ms 512 KB Output is correct
9 Correct 95 ms 640 KB Output is correct
10 Correct 238 ms 888 KB Output is correct
11 Correct 230 ms 768 KB Output is correct
12 Correct 225 ms 768 KB Output is correct
13 Correct 225 ms 888 KB Output is correct
14 Correct 314 ms 768 KB Output is correct
15 Correct 326 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 384 KB Output is correct
2 Correct 11 ms 384 KB Output is correct
3 Correct 73 ms 512 KB Output is correct
4 Correct 179 ms 768 KB Output is correct
5 Correct 57 ms 640 KB Output is correct
6 Correct 86 ms 764 KB Output is correct
7 Correct 154 ms 640 KB Output is correct
8 Correct 48 ms 512 KB Output is correct
9 Correct 95 ms 640 KB Output is correct
10 Correct 238 ms 888 KB Output is correct
11 Correct 230 ms 768 KB Output is correct
12 Correct 225 ms 768 KB Output is correct
13 Correct 225 ms 888 KB Output is correct
14 Correct 314 ms 768 KB Output is correct
15 Correct 326 ms 900 KB Output is correct
16 Correct 119 ms 688 KB Output is correct
17 Correct 142 ms 672 KB Output is correct
18 Correct 137 ms 760 KB Output is correct
19 Correct 33 ms 512 KB Output is correct
20 Correct 109 ms 512 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 32 ms 640 KB Output is correct
23 Correct 67 ms 672 KB Output is correct
24 Correct 27 ms 384 KB Output is correct
25 Correct 238 ms 824 KB Output is correct
26 Correct 232 ms 772 KB Output is correct
27 Correct 246 ms 812 KB Output is correct
28 Correct 238 ms 896 KB Output is correct
29 Correct 352 ms 888 KB Output is correct
30 Correct 337 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 384 KB Output is correct
2 Correct 11 ms 384 KB Output is correct
3 Correct 73 ms 512 KB Output is correct
4 Correct 179 ms 768 KB Output is correct
5 Correct 57 ms 640 KB Output is correct
6 Correct 86 ms 764 KB Output is correct
7 Correct 154 ms 640 KB Output is correct
8 Correct 48 ms 512 KB Output is correct
9 Correct 95 ms 640 KB Output is correct
10 Correct 238 ms 888 KB Output is correct
11 Correct 230 ms 768 KB Output is correct
12 Correct 225 ms 768 KB Output is correct
13 Correct 225 ms 888 KB Output is correct
14 Correct 314 ms 768 KB Output is correct
15 Correct 326 ms 900 KB Output is correct
16 Correct 205 ms 760 KB Output is correct
17 Correct 122 ms 512 KB Output is correct
18 Correct 28 ms 512 KB Output is correct
19 Correct 8 ms 384 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 8 ms 640 KB Output is correct
22 Correct 88 ms 640 KB Output is correct
23 Correct 17 ms 384 KB Output is correct
24 Correct 157 ms 692 KB Output is correct
25 Correct 222 ms 896 KB Output is correct
26 Correct 224 ms 808 KB Output is correct
27 Correct 221 ms 768 KB Output is correct
28 Correct 262 ms 888 KB Output is correct
29 Correct 336 ms 768 KB Output is correct
30 Correct 342 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 416 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 14 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 11 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 29 ms 384 KB Output is correct
22 Correct 11 ms 384 KB Output is correct
23 Correct 73 ms 512 KB Output is correct
24 Correct 179 ms 768 KB Output is correct
25 Correct 57 ms 640 KB Output is correct
26 Correct 86 ms 764 KB Output is correct
27 Correct 154 ms 640 KB Output is correct
28 Correct 48 ms 512 KB Output is correct
29 Correct 95 ms 640 KB Output is correct
30 Correct 238 ms 888 KB Output is correct
31 Correct 230 ms 768 KB Output is correct
32 Correct 225 ms 768 KB Output is correct
33 Correct 225 ms 888 KB Output is correct
34 Correct 314 ms 768 KB Output is correct
35 Correct 326 ms 900 KB Output is correct
36 Correct 119 ms 688 KB Output is correct
37 Correct 142 ms 672 KB Output is correct
38 Correct 137 ms 760 KB Output is correct
39 Correct 33 ms 512 KB Output is correct
40 Correct 109 ms 512 KB Output is correct
41 Correct 6 ms 384 KB Output is correct
42 Correct 32 ms 640 KB Output is correct
43 Correct 67 ms 672 KB Output is correct
44 Correct 27 ms 384 KB Output is correct
45 Correct 238 ms 824 KB Output is correct
46 Correct 232 ms 772 KB Output is correct
47 Correct 246 ms 812 KB Output is correct
48 Correct 238 ms 896 KB Output is correct
49 Correct 352 ms 888 KB Output is correct
50 Correct 337 ms 888 KB Output is correct
51 Correct 205 ms 760 KB Output is correct
52 Correct 122 ms 512 KB Output is correct
53 Correct 28 ms 512 KB Output is correct
54 Correct 8 ms 384 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 8 ms 640 KB Output is correct
57 Correct 88 ms 640 KB Output is correct
58 Correct 17 ms 384 KB Output is correct
59 Correct 157 ms 692 KB Output is correct
60 Correct 222 ms 896 KB Output is correct
61 Correct 224 ms 808 KB Output is correct
62 Correct 221 ms 768 KB Output is correct
63 Correct 262 ms 888 KB Output is correct
64 Correct 336 ms 768 KB Output is correct
65 Correct 342 ms 768 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 308 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 416 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 175 ms 760 KB Output is correct
82 Correct 42 ms 512 KB Output is correct
83 Correct 81 ms 640 KB Output is correct
84 Correct 43 ms 640 KB Output is correct
85 Correct 73 ms 632 KB Output is correct
86 Correct 61 ms 512 KB Output is correct
87 Correct 11 ms 512 KB Output is correct
88 Correct 7 ms 384 KB Output is correct
89 Correct 27 ms 512 KB Output is correct
90 Correct 238 ms 888 KB Output is correct
91 Correct 222 ms 768 KB Output is correct
92 Correct 223 ms 768 KB Output is correct
93 Correct 222 ms 888 KB Output is correct
94 Correct 219 ms 888 KB Output is correct
95 Correct 217 ms 888 KB Output is correct
96 Correct 219 ms 768 KB Output is correct
97 Correct 222 ms 808 KB Output is correct
98 Correct 316 ms 892 KB Output is correct
99 Correct 322 ms 888 KB Output is correct
100 Correct 324 ms 888 KB Output is correct