Submission #680203

# Submission time Handle Problem Language Result Execution time Memory
680203 2023-01-10T08:10:57 Z abcvuitunggio Visiting Singapore (NOI20_visitingsingapore) C++17
100 / 100
363 ms 844 KB
#include <iostream>
#define int long long
using namespace std;
const int INF=1e18;
int dp[2][5001][2][2],k,n,m,a,b,v[1001],s[5001],t[5001],res=-INF;
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> k >> n >> m >> a >> b;
    for (int i=1;i<=k;i++)
        cin >> v[i];
    for (int i=1;i<=n;i++)
        cin >> s[i];
    for (int i=0;i<m;i++)
        cin >> t[i];
    for (int i=0;i<=m;i++){
        for (int j=0;j<2;j++)
            for (int k=0;k<2;k++){
                dp[n&1^1][i][j][k]=(i==m?0:a*k+b*(m-i));
                dp[n&1][i][j][k]=-INF;
            }
    }
    for (int i=n;i>=1;i--){
        for (int j=m;j>=0;j--){
            for (int k=0;k<2;k++)
                for (int l=0;l<2;l++){
                    dp[i&1][j][k][l]=max((j==m?0:a*k+b*(m-j)),dp[i&1^1][j][0][l]+a*k+b);
                    if (j==m)
                        continue;
                    dp[i&1][j][k][l]=max(dp[i&1][j][k][l],max((s[i]==t[j]?dp[i&1^1][j+1][1][1]+v[t[j]]:-INF),dp[i&1][j+1][k][0]+b+a*l));
                }
        }
        res=max(res,dp[i&1][0][1][1]);
    }
    cout << res;
}

Compilation message

VisitingSingapore.cpp: In function 'int32_t main()':
VisitingSingapore.cpp:18:21: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   18 |                 dp[n&1^1][i][j][k]=(i==m?0:a*k+b*(m-i));
      |                    ~^~
VisitingSingapore.cpp:26:67: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   26 |                     dp[i&1][j][k][l]=max((j==m?0:a*k+b*(m-j)),dp[i&1^1][j][0][l]+a*k+b);
      |                                                                  ~^~
VisitingSingapore.cpp:29:79: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   29 |                     dp[i&1][j][k][l]=max(dp[i&1][j][k][l],max((s[i]==t[j]?dp[i&1^1][j+1][1][1]+v[t[j]]:-INF),dp[i&1][j+1][k][0]+b+a*l));
      |                                                                              ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 12 ms 408 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 7 ms 396 KB Output is correct
10 Correct 15 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 7 ms 404 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 11 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 14 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 340 KB Output is correct
2 Correct 15 ms 340 KB Output is correct
3 Correct 111 ms 524 KB Output is correct
4 Correct 263 ms 724 KB Output is correct
5 Correct 78 ms 636 KB Output is correct
6 Correct 111 ms 512 KB Output is correct
7 Correct 212 ms 636 KB Output is correct
8 Correct 68 ms 496 KB Output is correct
9 Correct 132 ms 628 KB Output is correct
10 Correct 340 ms 740 KB Output is correct
11 Correct 319 ms 744 KB Output is correct
12 Correct 320 ms 844 KB Output is correct
13 Correct 331 ms 728 KB Output is correct
14 Correct 337 ms 716 KB Output is correct
15 Correct 363 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 340 KB Output is correct
2 Correct 15 ms 340 KB Output is correct
3 Correct 111 ms 524 KB Output is correct
4 Correct 263 ms 724 KB Output is correct
5 Correct 78 ms 636 KB Output is correct
6 Correct 111 ms 512 KB Output is correct
7 Correct 212 ms 636 KB Output is correct
8 Correct 68 ms 496 KB Output is correct
9 Correct 132 ms 628 KB Output is correct
10 Correct 340 ms 740 KB Output is correct
11 Correct 319 ms 744 KB Output is correct
12 Correct 320 ms 844 KB Output is correct
13 Correct 331 ms 728 KB Output is correct
14 Correct 337 ms 716 KB Output is correct
15 Correct 363 ms 720 KB Output is correct
16 Correct 171 ms 620 KB Output is correct
17 Correct 208 ms 600 KB Output is correct
18 Correct 189 ms 600 KB Output is correct
19 Correct 37 ms 492 KB Output is correct
20 Correct 128 ms 564 KB Output is correct
21 Correct 8 ms 340 KB Output is correct
22 Correct 42 ms 596 KB Output is correct
23 Correct 82 ms 592 KB Output is correct
24 Correct 33 ms 424 KB Output is correct
25 Correct 320 ms 724 KB Output is correct
26 Correct 320 ms 748 KB Output is correct
27 Correct 323 ms 724 KB Output is correct
28 Correct 326 ms 724 KB Output is correct
29 Correct 349 ms 724 KB Output is correct
30 Correct 340 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 340 KB Output is correct
2 Correct 15 ms 340 KB Output is correct
3 Correct 111 ms 524 KB Output is correct
4 Correct 263 ms 724 KB Output is correct
5 Correct 78 ms 636 KB Output is correct
6 Correct 111 ms 512 KB Output is correct
7 Correct 212 ms 636 KB Output is correct
8 Correct 68 ms 496 KB Output is correct
9 Correct 132 ms 628 KB Output is correct
10 Correct 340 ms 740 KB Output is correct
11 Correct 319 ms 744 KB Output is correct
12 Correct 320 ms 844 KB Output is correct
13 Correct 331 ms 728 KB Output is correct
14 Correct 337 ms 716 KB Output is correct
15 Correct 363 ms 720 KB Output is correct
16 Correct 276 ms 692 KB Output is correct
17 Correct 129 ms 468 KB Output is correct
18 Correct 39 ms 516 KB Output is correct
19 Correct 10 ms 340 KB Output is correct
20 Correct 6 ms 468 KB Output is correct
21 Correct 8 ms 664 KB Output is correct
22 Correct 124 ms 596 KB Output is correct
23 Correct 24 ms 340 KB Output is correct
24 Correct 224 ms 640 KB Output is correct
25 Correct 323 ms 752 KB Output is correct
26 Correct 332 ms 724 KB Output is correct
27 Correct 320 ms 724 KB Output is correct
28 Correct 323 ms 724 KB Output is correct
29 Correct 340 ms 724 KB Output is correct
30 Correct 339 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 12 ms 408 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 7 ms 396 KB Output is correct
10 Correct 15 ms 424 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 7 ms 404 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 11 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 14 ms 432 KB Output is correct
21 Correct 33 ms 340 KB Output is correct
22 Correct 15 ms 340 KB Output is correct
23 Correct 111 ms 524 KB Output is correct
24 Correct 263 ms 724 KB Output is correct
25 Correct 78 ms 636 KB Output is correct
26 Correct 111 ms 512 KB Output is correct
27 Correct 212 ms 636 KB Output is correct
28 Correct 68 ms 496 KB Output is correct
29 Correct 132 ms 628 KB Output is correct
30 Correct 340 ms 740 KB Output is correct
31 Correct 319 ms 744 KB Output is correct
32 Correct 320 ms 844 KB Output is correct
33 Correct 331 ms 728 KB Output is correct
34 Correct 337 ms 716 KB Output is correct
35 Correct 363 ms 720 KB Output is correct
36 Correct 171 ms 620 KB Output is correct
37 Correct 208 ms 600 KB Output is correct
38 Correct 189 ms 600 KB Output is correct
39 Correct 37 ms 492 KB Output is correct
40 Correct 128 ms 564 KB Output is correct
41 Correct 8 ms 340 KB Output is correct
42 Correct 42 ms 596 KB Output is correct
43 Correct 82 ms 592 KB Output is correct
44 Correct 33 ms 424 KB Output is correct
45 Correct 320 ms 724 KB Output is correct
46 Correct 320 ms 748 KB Output is correct
47 Correct 323 ms 724 KB Output is correct
48 Correct 326 ms 724 KB Output is correct
49 Correct 349 ms 724 KB Output is correct
50 Correct 340 ms 724 KB Output is correct
51 Correct 276 ms 692 KB Output is correct
52 Correct 129 ms 468 KB Output is correct
53 Correct 39 ms 516 KB Output is correct
54 Correct 10 ms 340 KB Output is correct
55 Correct 6 ms 468 KB Output is correct
56 Correct 8 ms 664 KB Output is correct
57 Correct 124 ms 596 KB Output is correct
58 Correct 24 ms 340 KB Output is correct
59 Correct 224 ms 640 KB Output is correct
60 Correct 323 ms 752 KB Output is correct
61 Correct 332 ms 724 KB Output is correct
62 Correct 320 ms 724 KB Output is correct
63 Correct 323 ms 724 KB Output is correct
64 Correct 340 ms 724 KB Output is correct
65 Correct 339 ms 724 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 0 ms 324 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 0 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 0 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 324 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 324 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 260 ms 708 KB Output is correct
82 Correct 62 ms 468 KB Output is correct
83 Correct 118 ms 628 KB Output is correct
84 Correct 61 ms 596 KB Output is correct
85 Correct 103 ms 468 KB Output is correct
86 Correct 88 ms 520 KB Output is correct
87 Correct 17 ms 456 KB Output is correct
88 Correct 11 ms 412 KB Output is correct
89 Correct 37 ms 468 KB Output is correct
90 Correct 348 ms 724 KB Output is correct
91 Correct 332 ms 744 KB Output is correct
92 Correct 319 ms 724 KB Output is correct
93 Correct 322 ms 828 KB Output is correct
94 Correct 323 ms 728 KB Output is correct
95 Correct 321 ms 724 KB Output is correct
96 Correct 323 ms 724 KB Output is correct
97 Correct 324 ms 724 KB Output is correct
98 Correct 348 ms 736 KB Output is correct
99 Correct 343 ms 724 KB Output is correct
100 Correct 349 ms 720 KB Output is correct