제출 #456230

#제출 시각아이디문제언어결과실행 시간메모리
456230astoriaVisiting Singapore (NOI20_visitingsingapore)C++14
100 / 100
368 ms196388 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int k,n,m,a,b; cin >> k >> n >> m >> a >> b; int v[k+5]; for (int i=1; i<=k; i++) cin >> v[i]; int day[n+5]; for (int i=1; i<=n; i++) cin >> day[i]; int ord[m+5]; for (int i=1; i<=m; i++) cin >> ord[i]; int dp[2][m+5][2]; for (int i=0; i<2; i++){ for (int j=0; j<m+5; j++){ dp[i][j][0] = -1e9 - 200; dp[i][j][1] = -1e9 - 200; } } dp[0][0][0] = 0; dp[0][0][1] = 0; dp[1][0][0] = 0; dp[1][0][1] = 0; int storage[n+5][m+5]; for (int i=0; i<(m+5); i++) storage[0][i] = max(dp[0][i][0],dp[0][i][1]); /*for (int i=1; i<=n; i++){ dp[i][0][0] = 0; dp[i][0][1] = 0; //you don't need to go to singapore yet. }*/ int bst[n+5][m+5]; for (int j=1; j<=m; j++){ bst[0][j] = (j*b); //you have jumped some event } bst[0][0] = -1e9 - 200; //not possible if jump //cout << "HEHE" << endl; for (int i=1; i<=n; i++){ for (int j=1; j<=m; j++){ dp[1][j][0] = max(dp[0][j][0] + b,dp[0][j][1] + a + b); if (day[i]==ord[j]){ dp[1][j][1] = max(bst[i-1][j-1] + a, max(dp[0][j-1][1],dp[0][j-1][0])) + v[day[i]]; } else dp[1][j][1] = -1e9 - 200; } bst[i][0] = -1e9 - 200; //impossible if jump forced for (int j=1; j<=m; j++){ bst[i][j] = max(bst[i][j-1]+b, max(dp[1][j-1][1],dp[1][j-1][0])+b); } for (int j=0; j<=m; j++) storage[i][j] = max(dp[1][j][0],dp[1][j][1]); for (int j=0; j<=m; j++) dp[0][j][0] = dp[1][j][0], dp[0][j][1] = dp[1][j][1]; } int mx = -1e9 - 200; for (int i=0; i<=n; i++){ for (int j=0; j<=m; j++){ int val = storage[i][j] + a + (m-j)*b; if (j==m) val -= a; mx = max(mx,val); } } /*for (int i=0; i<=n; i++){ for (int j=0; j<=m; j++){ cout << "(" << dp[i][j][0] << ',' << dp[i][j][1] << ") "; } cout << endl; }*/ int nov= a + (b*m); cout << max(mx,nov); }
#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...