Submission #294829

# Submission time Handle Problem Language Result Execution time Memory
294829 2020-09-09T09:50:29 Z crossing0ver Visiting Singapore (NOI20_visitingsingapore) C++17
29 / 100
346 ms 196216 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];
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 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;
    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;
            if (j!=1)
            dp[i][j][0] = max(dp[i][j][0],dp[i][j-1][1] + a +  b);
        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);
        //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][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[5][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:7:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 14 ms 10752 KB Output is correct
3 Correct 1 ms 1408 KB Output is correct
4 Correct 3 ms 3968 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 8 ms 7168 KB Output is correct
10 Correct 18 ms 12268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 4 ms 3328 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 8 ms 6528 KB Output is correct
7 Correct 10 ms 6144 KB Output is correct
8 Correct 13 ms 9064 KB Output is correct
9 Correct 2 ms 1792 KB Output is correct
10 Correct 18 ms 12156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 29976 KB Output is correct
2 Correct 17 ms 18304 KB Output is correct
3 Correct 86 ms 79900 KB Output is correct
4 Correct 207 ms 174328 KB Output is correct
5 Correct 65 ms 51448 KB Output is correct
6 Correct 89 ms 76280 KB Output is correct
7 Correct 163 ms 143436 KB Output is correct
8 Correct 57 ms 54904 KB Output is correct
9 Correct 102 ms 91512 KB Output is correct
10 Correct 250 ms 196088 KB Output is correct
11 Correct 230 ms 195576 KB Output is correct
12 Correct 231 ms 196088 KB Output is correct
13 Correct 230 ms 196088 KB Output is correct
14 Correct 312 ms 196088 KB Output is correct
15 Correct 313 ms 196088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 29976 KB Output is correct
2 Correct 17 ms 18304 KB Output is correct
3 Correct 86 ms 79900 KB Output is correct
4 Correct 207 ms 174328 KB Output is correct
5 Correct 65 ms 51448 KB Output is correct
6 Correct 89 ms 76280 KB Output is correct
7 Correct 163 ms 143436 KB Output is correct
8 Correct 57 ms 54904 KB Output is correct
9 Correct 102 ms 91512 KB Output is correct
10 Correct 250 ms 196088 KB Output is correct
11 Correct 230 ms 195576 KB Output is correct
12 Correct 231 ms 196088 KB Output is correct
13 Correct 230 ms 196088 KB Output is correct
14 Correct 312 ms 196088 KB Output is correct
15 Correct 313 ms 196088 KB Output is correct
16 Correct 131 ms 117752 KB Output is correct
17 Correct 157 ms 142456 KB Output is correct
18 Correct 142 ms 129144 KB Output is correct
19 Correct 30 ms 26880 KB Output is correct
20 Correct 103 ms 92924 KB Output is correct
21 Correct 9 ms 9984 KB Output is correct
22 Correct 34 ms 28920 KB Output is correct
23 Correct 65 ms 57080 KB Output is correct
24 Correct 29 ms 29048 KB Output is correct
25 Correct 230 ms 195576 KB Output is correct
26 Correct 229 ms 195704 KB Output is correct
27 Correct 230 ms 196216 KB Output is correct
28 Correct 229 ms 196088 KB Output is correct
29 Correct 313 ms 195704 KB Output is correct
30 Correct 346 ms 195864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 29976 KB Output is correct
2 Correct 17 ms 18304 KB Output is correct
3 Correct 86 ms 79900 KB Output is correct
4 Correct 207 ms 174328 KB Output is correct
5 Correct 65 ms 51448 KB Output is correct
6 Correct 89 ms 76280 KB Output is correct
7 Correct 163 ms 143436 KB Output is correct
8 Correct 57 ms 54904 KB Output is correct
9 Correct 102 ms 91512 KB Output is correct
10 Correct 250 ms 196088 KB Output is correct
11 Correct 230 ms 195576 KB Output is correct
12 Correct 231 ms 196088 KB Output is correct
13 Correct 230 ms 196088 KB Output is correct
14 Correct 312 ms 196088 KB Output is correct
15 Correct 313 ms 196088 KB Output is correct
16 Incorrect 203 ms 182392 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB Output is correct
2 Correct 14 ms 10752 KB Output is correct
3 Correct 1 ms 1408 KB Output is correct
4 Correct 3 ms 3968 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 8 ms 7168 KB Output is correct
10 Correct 18 ms 12268 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 4 ms 3328 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 2 ms 1536 KB Output is correct
16 Correct 8 ms 6528 KB Output is correct
17 Correct 10 ms 6144 KB Output is correct
18 Correct 13 ms 9064 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 18 ms 12156 KB Output is correct
21 Correct 29 ms 29976 KB Output is correct
22 Correct 17 ms 18304 KB Output is correct
23 Correct 86 ms 79900 KB Output is correct
24 Correct 207 ms 174328 KB Output is correct
25 Correct 65 ms 51448 KB Output is correct
26 Correct 89 ms 76280 KB Output is correct
27 Correct 163 ms 143436 KB Output is correct
28 Correct 57 ms 54904 KB Output is correct
29 Correct 102 ms 91512 KB Output is correct
30 Correct 250 ms 196088 KB Output is correct
31 Correct 230 ms 195576 KB Output is correct
32 Correct 231 ms 196088 KB Output is correct
33 Correct 230 ms 196088 KB Output is correct
34 Correct 312 ms 196088 KB Output is correct
35 Correct 313 ms 196088 KB Output is correct
36 Correct 131 ms 117752 KB Output is correct
37 Correct 157 ms 142456 KB Output is correct
38 Correct 142 ms 129144 KB Output is correct
39 Correct 30 ms 26880 KB Output is correct
40 Correct 103 ms 92924 KB Output is correct
41 Correct 9 ms 9984 KB Output is correct
42 Correct 34 ms 28920 KB Output is correct
43 Correct 65 ms 57080 KB Output is correct
44 Correct 29 ms 29048 KB Output is correct
45 Correct 230 ms 195576 KB Output is correct
46 Correct 229 ms 195704 KB Output is correct
47 Correct 230 ms 196216 KB Output is correct
48 Correct 229 ms 196088 KB Output is correct
49 Correct 313 ms 195704 KB Output is correct
50 Correct 346 ms 195864 KB Output is correct
51 Incorrect 203 ms 182392 KB Output isn't correct
52 Halted 0 ms 0 KB -