Submission #294973

# Submission time Handle Problem Language Result Execution time Memory
294973 2020-09-09T11:22:47 Z crossing0ver Visiting Singapore (NOI20_visitingsingapore) C++17
23 / 100
301 ms 262148 KB
#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][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[0][j][1][y] = inf,dp[0][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 = 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[i][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[i][j][0][0],c + dp[i-1][j-1][x][y]);
           }

           dp[i][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[i][j][0][1],c + dp[i-1][j][x][1]);
           }


           if (s[i] != t[j]) dp[i][j][1][1] = inf;
           else {
                int adit = hap[ t[j] ];
            dp[i][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[i][j][1][1],adit + dp[i-1][j-1][x][y]);
           }
           }

           dp[i][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[i][j][1][0],dp[i][j-1][1][y] + c);
           }
           for (int x = 0 ; x < 2; x++)
            for (int  y= 0 ; y < 2; y++)
            change(ans,dp[i][j][x][y] + (y ? (j == m ? 0 : a ) + (m-j)*b : (m - j)*b));
           /*
           dp[i][j][0][0] = dp[i-1][j-1][0][0] + b + b;
           dp[i][j][0][0] = dp[i-1][j-1][0][0] + b + b;
           dp[i][j][0][0]
           dp[i][j][0] = a + j*b + b+a;
            if (j!=1)
            dp[i][j][0] = max(dp[i][j][0],dp[i][j-1][1]  +  a + b);
    //        if (i>1)
    //    dp[i][j][0] = max(dp[i][j][0],dp[i-1][j][0]+b);
       // else
       // dp[i][j][0] = max(dp[i][j][0],dp[i-1][j][0]+b);
        if (j != 1)
        dp[i][j][0] = max(dp[i][j][0],dp[i][j-1][0]+b);

        dp[i][j][0] = max(dp[i][j][0],dp[i-1][j][1] + a + b + b + a);
        dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][0] + 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][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 << 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

VisitingSingapore.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 20 ms 17536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 7 ms 7168 KB Output is correct
7 Correct 1 ms 1280 KB Output is correct
8 Correct 3 ms 3328 KB Output is correct
9 Correct 12 ms 11008 KB Output is correct
10 Correct 23 ms 20096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 6 ms 5248 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 2048 KB Output is correct
6 Correct 12 ms 10240 KB Output is correct
7 Correct 11 ms 9856 KB Output is correct
8 Correct 17 ms 14464 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 23 ms 20088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 49016 KB Output is correct
2 Correct 27 ms 25848 KB Output is correct
3 Correct 173 ms 144248 KB Output is correct
4 Runtime error 301 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 49016 KB Output is correct
2 Correct 27 ms 25848 KB Output is correct
3 Correct 173 ms 144248 KB Output is correct
4 Runtime error 301 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 49016 KB Output is correct
2 Correct 27 ms 25848 KB Output is correct
3 Correct 173 ms 144248 KB Output is correct
4 Runtime error 301 ms 262148 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 896 KB Output is correct
11 Correct 1 ms 896 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 896 KB Output is correct
15 Correct 1 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 20 ms 17536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 7 ms 7168 KB Output is correct
7 Correct 1 ms 1280 KB Output is correct
8 Correct 3 ms 3328 KB Output is correct
9 Correct 12 ms 11008 KB Output is correct
10 Correct 23 ms 20096 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 6 ms 5248 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
16 Correct 12 ms 10240 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 17 ms 14464 KB Output is correct
19 Correct 2 ms 2432 KB Output is correct
20 Correct 23 ms 20088 KB Output is correct
21 Correct 55 ms 49016 KB Output is correct
22 Correct 27 ms 25848 KB Output is correct
23 Correct 173 ms 144248 KB Output is correct
24 Runtime error 301 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -