Submission #294981

# Submission time Handle Problem Language Result Execution time Memory
294981 2020-09-09T11:31:17 Z crossing0ver Visiting Singapore (NOI20_visitingsingapore) C++17
100 / 100
415 ms 668 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][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

VisitingSingapore.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 18 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 13 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 17 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 428 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 113 ms 384 KB Output is correct
4 Correct 292 ms 632 KB Output is correct
5 Correct 87 ms 512 KB Output is correct
6 Correct 119 ms 512 KB Output is correct
7 Correct 222 ms 632 KB Output is correct
8 Correct 83 ms 384 KB Output is correct
9 Correct 157 ms 544 KB Output is correct
10 Correct 343 ms 632 KB Output is correct
11 Correct 353 ms 512 KB Output is correct
12 Correct 356 ms 632 KB Output is correct
13 Correct 320 ms 512 KB Output is correct
14 Correct 396 ms 632 KB Output is correct
15 Correct 406 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 428 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 113 ms 384 KB Output is correct
4 Correct 292 ms 632 KB Output is correct
5 Correct 87 ms 512 KB Output is correct
6 Correct 119 ms 512 KB Output is correct
7 Correct 222 ms 632 KB Output is correct
8 Correct 83 ms 384 KB Output is correct
9 Correct 157 ms 544 KB Output is correct
10 Correct 343 ms 632 KB Output is correct
11 Correct 353 ms 512 KB Output is correct
12 Correct 356 ms 632 KB Output is correct
13 Correct 320 ms 512 KB Output is correct
14 Correct 396 ms 632 KB Output is correct
15 Correct 406 ms 512 KB Output is correct
16 Correct 174 ms 548 KB Output is correct
17 Correct 209 ms 632 KB Output is correct
18 Correct 191 ms 512 KB Output is correct
19 Correct 39 ms 504 KB Output is correct
20 Correct 149 ms 508 KB Output is correct
21 Correct 9 ms 384 KB Output is correct
22 Correct 44 ms 512 KB Output is correct
23 Correct 87 ms 512 KB Output is correct
24 Correct 32 ms 384 KB Output is correct
25 Correct 405 ms 604 KB Output is correct
26 Correct 403 ms 632 KB Output is correct
27 Correct 355 ms 632 KB Output is correct
28 Correct 324 ms 512 KB Output is correct
29 Correct 401 ms 512 KB Output is correct
30 Correct 411 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 428 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 113 ms 384 KB Output is correct
4 Correct 292 ms 632 KB Output is correct
5 Correct 87 ms 512 KB Output is correct
6 Correct 119 ms 512 KB Output is correct
7 Correct 222 ms 632 KB Output is correct
8 Correct 83 ms 384 KB Output is correct
9 Correct 157 ms 544 KB Output is correct
10 Correct 343 ms 632 KB Output is correct
11 Correct 353 ms 512 KB Output is correct
12 Correct 356 ms 632 KB Output is correct
13 Correct 320 ms 512 KB Output is correct
14 Correct 396 ms 632 KB Output is correct
15 Correct 406 ms 512 KB Output is correct
16 Correct 292 ms 568 KB Output is correct
17 Correct 144 ms 384 KB Output is correct
18 Correct 47 ms 384 KB Output is correct
19 Correct 13 ms 384 KB Output is correct
20 Correct 7 ms 384 KB Output is correct
21 Correct 12 ms 512 KB Output is correct
22 Correct 146 ms 512 KB Output is correct
23 Correct 27 ms 384 KB Output is correct
24 Correct 233 ms 540 KB Output is correct
25 Correct 364 ms 632 KB Output is correct
26 Correct 342 ms 512 KB Output is correct
27 Correct 345 ms 632 KB Output is correct
28 Correct 328 ms 512 KB Output is correct
29 Correct 399 ms 632 KB Output is correct
30 Correct 411 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 18 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 13 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 36 ms 428 KB Output is correct
22 Correct 15 ms 384 KB Output is correct
23 Correct 113 ms 384 KB Output is correct
24 Correct 292 ms 632 KB Output is correct
25 Correct 87 ms 512 KB Output is correct
26 Correct 119 ms 512 KB Output is correct
27 Correct 222 ms 632 KB Output is correct
28 Correct 83 ms 384 KB Output is correct
29 Correct 157 ms 544 KB Output is correct
30 Correct 343 ms 632 KB Output is correct
31 Correct 353 ms 512 KB Output is correct
32 Correct 356 ms 632 KB Output is correct
33 Correct 320 ms 512 KB Output is correct
34 Correct 396 ms 632 KB Output is correct
35 Correct 406 ms 512 KB Output is correct
36 Correct 174 ms 548 KB Output is correct
37 Correct 209 ms 632 KB Output is correct
38 Correct 191 ms 512 KB Output is correct
39 Correct 39 ms 504 KB Output is correct
40 Correct 149 ms 508 KB Output is correct
41 Correct 9 ms 384 KB Output is correct
42 Correct 44 ms 512 KB Output is correct
43 Correct 87 ms 512 KB Output is correct
44 Correct 32 ms 384 KB Output is correct
45 Correct 405 ms 604 KB Output is correct
46 Correct 403 ms 632 KB Output is correct
47 Correct 355 ms 632 KB Output is correct
48 Correct 324 ms 512 KB Output is correct
49 Correct 401 ms 512 KB Output is correct
50 Correct 411 ms 668 KB Output is correct
51 Correct 292 ms 568 KB Output is correct
52 Correct 144 ms 384 KB Output is correct
53 Correct 47 ms 384 KB Output is correct
54 Correct 13 ms 384 KB Output is correct
55 Correct 7 ms 384 KB Output is correct
56 Correct 12 ms 512 KB Output is correct
57 Correct 146 ms 512 KB Output is correct
58 Correct 27 ms 384 KB Output is correct
59 Correct 233 ms 540 KB Output is correct
60 Correct 364 ms 632 KB Output is correct
61 Correct 342 ms 512 KB Output is correct
62 Correct 345 ms 632 KB Output is correct
63 Correct 328 ms 512 KB Output is correct
64 Correct 399 ms 632 KB Output is correct
65 Correct 411 ms 512 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 0 ms 384 KB Output is correct
69 Correct 0 ms 384 KB Output is correct
70 Correct 0 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 0 ms 256 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 265 ms 584 KB Output is correct
82 Correct 62 ms 384 KB Output is correct
83 Correct 123 ms 552 KB Output is correct
84 Correct 63 ms 512 KB Output is correct
85 Correct 108 ms 516 KB Output is correct
86 Correct 90 ms 384 KB Output is correct
87 Correct 16 ms 384 KB Output is correct
88 Correct 13 ms 384 KB Output is correct
89 Correct 44 ms 384 KB Output is correct
90 Correct 415 ms 512 KB Output is correct
91 Correct 351 ms 632 KB Output is correct
92 Correct 364 ms 588 KB Output is correct
93 Correct 339 ms 632 KB Output is correct
94 Correct 402 ms 632 KB Output is correct
95 Correct 330 ms 632 KB Output is correct
96 Correct 368 ms 632 KB Output is correct
97 Correct 415 ms 632 KB Output is correct
98 Correct 401 ms 572 KB Output is correct
99 Correct 410 ms 632 KB Output is correct
100 Correct 409 ms 512 KB Output is correct