답안 #680187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680187 2023-01-10T07:31:36 Z fdnfksd Visiting Singapore (NOI20_visitingsingapore) C++14
10 / 100
55 ms 90444 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=5005;
const ll inf=2e9;
ll mn[5005][5005],mn2[5005][5005],mn1[5005][5005];
void update(ll i,ll j,ll val)
{
    mn1[i][j]=max(mn1[i][j-1],val);
    mn2[i][j]=max(mn2[i-1][j],val);
    mn[i][j]=max({mn[i-1][j],mn[i][j-1],val});
}
ll k,n,m,a,b,s[maxN],v[101],t[maxN];
long long dp[5005][5005];
void solve()
{
    cin >> k >> n >> m >> a >> b;
    for(int i=1;i<=k;i++) cin >> v[i];
    for(int i=1;i<=n;i++) cin >> s[i];
    for(int i=1;i<=m;i++) cin >> t[i];
    mn[0][0]=mn1[0][0]=mn2[0][0]=-inf;
    for(int i=1;i<=n;i++)
    {
        mn[i][0]=mn[0][i]=mn1[i][0]=mn1[0][i]=mn2[0][i]=mn2[i][0]=-inf;
    }
    dp[0][0]=0;
    long long ans=-inf;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i]==t[j])
            {
                dp[i][j]=v[s[i]]+(a*(j>1)+b*(j-1));
                ll x;
                x=mn1[i-1][j-1];
                dp[i][j]=max(dp[i][j],1ll*x+i*b+j*b-2*b+a+v[s[i]]);
                x=mn2[i-1][j-1];
                dp[i][j]=max(dp[i][j],1ll*x+i*b+j*b-2*b+a+v[s[i]]);
                if(i>=2&&j>=2)
                {
                    x=mn[i-2][j-2];
                    dp[i][j]=max(dp[i][j],1ll*x+i*b+j*b-2*b+2*a+v[s[i]]);
                }
                if(i>1&&j>1) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+v[s[i]]);
            }
            else
            {
                dp[i][j]=-inf;
            }
            update(i,j,dp[i][j]-b*i-b*j);
            ans=max(ans,1ll*dp[i][j]+(a*(m>j)+b*(m-j)));
        }
    }
    cout << ans;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 24 ms 32212 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 8 ms 14676 KB Output is correct
5 Correct 2 ms 6228 KB Output is correct
6 Correct 10 ms 17364 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 16 ms 22100 KB Output is correct
10 Correct 35 ms 36028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 8 ms 9684 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 14 ms 19412 KB Output is correct
7 Correct 15 ms 17876 KB Output is correct
8 Correct 22 ms 26920 KB Output is correct
9 Correct 3 ms 5332 KB Output is correct
10 Correct 27 ms 35960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 90444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 90444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 90444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 0 ms 852 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 1 ms 2116 KB Output is correct
11 Correct 1 ms 2132 KB Output is correct
12 Correct 1 ms 2132 KB Output is correct
13 Incorrect 1 ms 2004 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 24 ms 32212 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 8 ms 14676 KB Output is correct
5 Correct 2 ms 6228 KB Output is correct
6 Correct 10 ms 17364 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 16 ms 22100 KB Output is correct
10 Correct 35 ms 36028 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 0 ms 596 KB Output is correct
13 Correct 8 ms 9684 KB Output is correct
14 Correct 1 ms 1620 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
16 Correct 14 ms 19412 KB Output is correct
17 Correct 15 ms 17876 KB Output is correct
18 Correct 22 ms 26920 KB Output is correct
19 Correct 3 ms 5332 KB Output is correct
20 Correct 27 ms 35960 KB Output is correct
21 Incorrect 55 ms 90444 KB Output isn't correct
22 Halted 0 ms 0 KB -