이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
VisitingSingapore.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main(){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |