Submission #233979

#TimeUsernameProblemLanguageResultExecution timeMemory
233979WannnabeIOIVisiting Singapore (NOI20_visitingsingapore)C++14
100 / 100
183 ms760 KiB
#include <bits/stdc++.h>
using namespace std;
 
const int mn = -2e9;
 
int K, M, N, A, B;
int V[1005], S[5005], T[5005]; 
int dp[5][5005][5];
 
int main() {
  ios_base::sync_with_stdio(false); 
  cin.tie (NULL); 
  cout.tie (NULL); 
//  freopen("inp", "r", stdin);
  scanf("%d %d %d %d %d", &K, &N, &M, &A, &B);
  for(int i = 1; i <= K; i++) scanf("%d", &V[i]);
  for(int i = 1; i <= N; i++) scanf("%d", &S[i]);
  for(int i = 1; i <= M; i++) scanf("%d", &T[i]);
  for(int i = 0; i <= M; i++) {
    for(int j = 1; j <= 4; j++) {
      dp[0][i][j] = mn;
    }
  }
  int ans = A + M * B;
  for(int i = 1; i <= N; i++) {
    int now = i % 2, bef = !now;
    for(int k = 1; k <= 4; k++) dp[now][0][k] = mn;
    for(int j = 1; j <= M; j++) {
      if(S[i] == T[j]) {
        int opt = (j == 1 ? 0 : (A + (j - 1) * B));
        for(int k = 1; k <= 4; k++) {
          opt = max(opt, dp[bef][j - 1][k]);
        }
        dp[now][j][4] = opt + V[S[i]];
      }else {
        dp[now][j][4] = mn;
      }
      //if you don't take T[j - 1] beforehand
      dp[now][j][2] = max(dp[now][j - 1][2] + B, dp[now][j - 1][4] + A + B);
      dp[now][j][3] = max(dp[bef][j][3] + B, dp[bef][j][4] + A + B);
      dp[now][j][1] = max(dp[now][j - 1][3] + A + B, max(dp[now][j - 1][1] + B, 2*A + (j + 1)*B));
    }
    for(int k = 1; k <= 4; k++) {
//      cout << i << " " << k << " " << dp[now][M][k] << "\n";
      ans = max(ans, dp[now][M][k]);
    }
  }
  printf("%d\n", ans);
}

Compilation message (stderr)

VisitingSingapore.cpp: In function 'int main()':
VisitingSingapore.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d %d", &K, &N, &M, &A, &B);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VisitingSingapore.cpp:16:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= K; i++) scanf("%d", &V[i]);
                               ~~~~~^~~~~~~~~~~~~
VisitingSingapore.cpp:17:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= N; i++) scanf("%d", &S[i]);
                               ~~~~~^~~~~~~~~~~~~
VisitingSingapore.cpp:18:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= M; i++) scanf("%d", &T[i]);
                               ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...