| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 294768 | crossing0ver | Visiting Singapore (NOI20_visitingsingapore) | C++17 | 24 ms | 29952 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
int k,n,m,a,b,hap[5005],s[5005],t[5005];
int dp[5005][5005][2];
main() {
cin >> k >> n >> m >> a >> b;
for (int i = 1; i <= k; i++)
cin >> hap[i];
for (int i = 1; i <= n; i++)
cin >> s[i];
for (int i = 1; i <= m; i++)
cin >> t[i];
int ans = a + b*m;
const int inf = -1e6;
for (int i = 0; i <= n; i++)
for (int j = i+1; j <= m; j++)
dp[i][j][0] = dp[i][j][1] = inf;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
// dp[i][j]_ taken j-th one
// 0 _ last not used
// 1 _ last used
dp[i][j][0] = a + j*b;
dp[i][j][0] = max(dp[i][j][0],dp[i-1][j][0] + b);
dp[i][j][0] = max(dp[i][j][0],dp[i-1][j][1] + a + b);
//dp[i][j][0] = max(dp[i-1][j][0], dp[i-1][j][1] + a + b);
ans = max(ans,dp[i][j][0] + b*(m-j));
if (s[i] != t[j])
dp[i][j][1] = inf;
else {
int adit = hap[ t[j] ];
dp[i][j][1] = (j > 1? a : 0) + (j-1)*b + adit;
dp[i][j][1] = max(dp[i][j][1],adit + dp[i-1][j-1][1]);
dp[i][j][1] = max(dp[i][j][1],adit + dp[i-1][j-1][0]);
ans = max(ans,dp[i][j][1] + (m-j)*b + (j != m ? a : 0));
}
}
cout << ans;
/*
if (m <= n) {
ans = max(ans, hap[1]*m);
}else {
ans = max(ans,hap[1]*n + (m-n)*B + A);
}
cout << ans;*/
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
