답안 #224837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224837 2020-04-19T02:14:58 Z nabilervatra Visiting Singapore (NOI20_visitingsingapore) C++14
23 / 100
63 ms 30200 KB
#include <bits/stdc++.h>
using namespace std;
long long k,n,m,a,b,dp[5010][3][3],tab[5010][3][3],ans,arr[1010],s[5010],t[5010],dep[5005][5005];

int main(){
    cin>>k>>n>>m>>a>>b;
    
    for(long long i =1;i<=k;i++){
        cin>>arr[i];
    }
    for(long long i =1;i<=n;i++){
        cin>>s[i];
    }
    for(long long i =1;i<=m;i++){
        cin>>t[i];
    }
    if(a==b&&a==0){
        for(int i =1;i<=n;i++){
            for(int j =1;j<=m;j++){
                if(s[i]==t[j])dep[i][j]= arr[s[i]]+ dep[i-1][j-1];
                dep[i][j]= max(dep[i][j],max(dep[i-1][j],dep[i][j-1]));
            }
        }
        cout<<dep[n][m]<<endl;
        // return 0;
    }
    ans = -1e9;
    for(int j =0;j<=m;j++){
        tab[j][0][1]=-1e9;
        tab[j][0][0]=-1e9;
        tab[j][1][0]=-1e9;
        tab[j][1][1]=-1e9;
    }
    for(int i =1;i<=n;i++){
        for(int j =0;j<=m;j++){
            dp[j][0][1]=-1e9;
            dp[j][0][0]=-1e9;
            dp[j][1][0]=-1e9;
            dp[j][1][1]=-1e9;
        }
        tab[0][0][0]=0;
        dp[0][0][0]=0;
        for(int j =1;j<=m;j++){
            if(s[i]==t[j]){
                dp[j][0][0]=max(max(tab[j-1][0][0],tab[j-1][1][0]),max(tab[j-1][0][1],tab[j-1][1][1]))+arr[s[i]];
            }
            dp[j][1][0]= max(a+b+tab[j][0][0],b+tab[j][1][0]);
            dp[j][0][1]= max(a+b+dp[j-1][0][0],b+dp [j-1][0][1]);
            dp[j][1][1]= max(max(tab[j][0][1]+a+b,dp[j-1][1][0]+a+b),max(tab[j][1][1]+b,dp[j-1][1][1]+b));
        }
        ans = max(ans,max(max(dp[m][0][0],dp[m][1][0]),max(dp[m][0][1],dp[m][1][1])));
        for(int j=0;j<=m;j++){
            tab[j][0][0]=dp[j][0][0];
            tab[j][1][0]=dp[j][1][0];
            tab[j][0][1]=dp[j][0][1];
            tab[j][1][1]=dp[j][1][1];
        }

    }
    cout<<ans<<endl;
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 13 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 15 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 9 ms 512 KB Output is correct
8 Correct 13 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 15 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 30200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 30200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 30200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 13 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 15 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 8 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 10 ms 512 KB Output is correct
17 Correct 9 ms 512 KB Output is correct
18 Correct 13 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 15 ms 512 KB Output is correct
21 Incorrect 63 ms 30200 KB Output isn't correct
22 Halted 0 ms 0 KB -