Submission #298255

# Submission time Handle Problem Language Result Execution time Memory
298255 2020-09-12T16:28:57 Z beso123 Visiting Singapore (NOI20_visitingsingapore) C++14
23 / 100
171 ms 262148 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define inf -1e9
using namespace std;
const int N=5003;
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 24 ms 30844 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 3 ms 4480 KB Output is correct
5 Correct 1 ms 2048 KB Output is correct
6 Correct 8 ms 10880 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 4 ms 4480 KB Output is correct
9 Correct 14 ms 18560 KB Output is correct
10 Correct 30 ms 35960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 16 ms 17792 KB Output is correct
7 Correct 14 ms 17408 KB Output is correct
8 Correct 20 ms 25472 KB Output is correct
9 Correct 3 ms 3584 KB Output is correct
10 Correct 28 ms 35840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 87160 KB Output is correct
2 Correct 29 ms 41344 KB Output is correct
3 Runtime error 171 ms 262148 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 87160 KB Output is correct
2 Correct 29 ms 41344 KB Output is correct
3 Runtime error 171 ms 262148 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 87160 KB Output is correct
2 Correct 29 ms 41344 KB Output is correct
3 Runtime error 171 ms 262148 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 1 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 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 2 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 1024 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 24 ms 30844 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 3 ms 4480 KB Output is correct
5 Correct 1 ms 2048 KB Output is correct
6 Correct 8 ms 10880 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 4 ms 4480 KB Output is correct
9 Correct 14 ms 18560 KB Output is correct
10 Correct 30 ms 35960 KB Output is correct
11 Correct 1 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 16 ms 17792 KB Output is correct
17 Correct 14 ms 17408 KB Output is correct
18 Correct 20 ms 25472 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 28 ms 35840 KB Output is correct
21 Correct 56 ms 87160 KB Output is correct
22 Correct 29 ms 41344 KB Output is correct
23 Runtime error 171 ms 262148 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -