Submission #294981

#TimeUsernameProblemLanguageResultExecution timeMemory
294981crossing0verVisiting Singapore (NOI20_visitingsingapore)C++17
100 / 100
415 ms668 KiB
#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][2][2],old_dp[5005][2][2]; // //int dp[5005][5005][2][2]; void change(int& a,int b) { if (a < b) a = b; } 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 = -1e8; for (int j = 1; j <= m; j++) for (int y = 0; y < 2; y++) dp[j][1][y] = inf,dp[j][0][y] = a + b*j; // for (int i = 1; i <= n; i++) // for (int x = 0; x < 2; x++) // dp[i][0][x][1] =inf,dp[i][0][x][0] = a + b; // //for (int j = 1; j <= m ;j ++) /// dp[0][j][1] = inf,dp[0][j][0] = a + b*j; // for (int i = 1; i <= n; i++) // for (int j = 1; j <= m; j++) // dp[i][j][0] = dp[i][j][1] = inf; // dp[i][j][a1][a2] - already started for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) for (int x = 0; x < 2; x++) for (int y = 0; y < 2; y++) old_dp[j][x][y] = dp[j][x][y], dp[j][x][y] = 0; 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; //[0][0] // i_not used, j-not used dp[j][0][0] = a + j*b + a + b; for (int x = 0; x < 2; x++) for (int y = 0; y < 2; y++) { int c = 0; if (y == 0) c += b + (j == 1 ? a : 0); else c += a + b; if (x == 0) c += b + (i == 1 ? a : 0); else c += a + b; change(dp[j][0][0],c + old_dp[j-1][x][y]); } dp[j][0][1] = a + j*b + a + b; for (int x = 0; x < 2; x++){ int c = 0; if (x == 0) c += b + (i == 1 ? a : 0); else c += a + b; change(dp[j][0][1],c + old_dp[j][x][1]); } if (s[i] != t[j]) dp[j][1][1] = inf; else { int adit = hap[ t[j] ]; dp[j][1][1] = adit + (j-1)*b + (j > 1 ? a : 0); if (i != 1) for (int x = 0; x < 2; x++) for (int y = 0; y < 2; y++) { // int c = 0; //if (x == 0) c += (i == 1 ? ) change(dp[j][1][1],adit + old_dp[j-1][x][y]); } } dp[j][1][0] = a + b + a + j*b; for (int y = 0; y < 2; y++) { int c = 0; if (y == 0) c += b + (j == 1 ? a : 0); else c += a + b; change(dp[j][1][0],dp[j-1][1][y] + c); } for (int x = 0 ; x < 2; x++) for (int y= 0 ; y < 2; y++) change(ans,dp[j][x][y] + (y ? (j == m ? 0 : a ) + (m-j)*b : (m - j)*b)); } } // cout << dp[3][3][1][1];exit(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;*/ }

Compilation message (stderr)

VisitingSingapore.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      |      ^
#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...