Submission #298258

# Submission time Handle Problem Language Result Execution time Memory
298258 2020-09-12T16:33:33 Z beso123 Visiting Singapore (NOI20_visitingsingapore) C++14
23 / 100
165 ms 262144 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][N][4],h[N],s[N],t[N];
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<=n;k++){
    dp[k][0][0]=inf;
     dp[k][0][1]=inf;
      dp[k][0][2]=inf;
       dp[k][0][3]=inf;
}
for(int i=0;i<=m;i++){
    dp[0][i][0]=inf;
     dp[0][i][1]=inf;
      dp[0][i][2]=inf;
       dp[0][i][3]=inf;
}
for(int k=1;k<=n;k++){
    for(int i=1;i<=m;i++){
        dp[k][i][0]=max(dp[k][i-1][0],dp[k-1][i][0])+b;
        dp[k][i][1]=dp[k-1][i][1]+b;
        dp[k][i][2]=dp[k][i-1][2]+b;
        if(s[k]==t[i]){
        dp[k][i][3]=h[t[i]];
        if(i!=1)
            dp[k][i][3]+=a+(i-1)*b;
        dp[k][i][3]=max(dp[k][i][3],
                        max(dp[k-1][i-1][0]+(2*a)+h[t[i]],
                            max(dp[k-1][i-1][1]+a+h[t[i]],
                                max(dp[k-1][i-1][2]+a+h[t[i]],dp[k-1][i-1][3]+h[t[i]]))));
        dp[k][i][0]=max(dp[k][i][0],dp[k][i][3]);
        dp[k][i][1]=max(dp[k][i][1],dp[k][i][3]);
        dp[k][i][2]=max(dp[k][i][2],dp[k][i][3]);
        int pas=dp[k][i][3]+b*(m-i);
        if(i!=m)
            pas+=a;
        ans=max(ans,pas);
        }
        else dp[k][i][3]=inf;
    }
}
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 1664 KB Output is correct
2 Correct 23 ms 30976 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 3 ms 4480 KB Output is correct
5 Correct 2 ms 2048 KB Output is correct
6 Correct 8 ms 11008 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 6 ms 4480 KB Output is correct
9 Correct 14 ms 18516 KB Output is correct
10 Correct 29 ms 35964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 7 ms 8832 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 3 ms 3200 KB Output is correct
6 Correct 17 ms 17820 KB Output is correct
7 Correct 14 ms 17408 KB Output is correct
8 Correct 20 ms 25464 KB Output is correct
9 Correct 3 ms 3584 KB Output is correct
10 Correct 28 ms 35968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 87416 KB Output is correct
2 Correct 28 ms 41600 KB Output is correct
3 Runtime error 165 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 87416 KB Output is correct
2 Correct 28 ms 41600 KB Output is correct
3 Runtime error 165 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 87416 KB Output is correct
2 Correct 28 ms 41600 KB Output is correct
3 Runtime error 165 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 1 ms 1024 KB Output is correct
12 Correct 1 ms 1024 KB Output is correct
13 Correct 1 ms 1024 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1664 KB Output is correct
2 Correct 23 ms 30976 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 3 ms 4480 KB Output is correct
5 Correct 2 ms 2048 KB Output is correct
6 Correct 8 ms 11008 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 6 ms 4480 KB Output is correct
9 Correct 14 ms 18516 KB Output is correct
10 Correct 29 ms 35964 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 7 ms 8832 KB Output is correct
14 Correct 1 ms 1024 KB Output is correct
15 Correct 3 ms 3200 KB Output is correct
16 Correct 17 ms 17820 KB Output is correct
17 Correct 14 ms 17408 KB Output is correct
18 Correct 20 ms 25464 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 28 ms 35968 KB Output is correct
21 Correct 56 ms 87416 KB Output is correct
22 Correct 28 ms 41600 KB Output is correct
23 Runtime error 165 ms 262144 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -