답안 #340929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340929 2020-12-28T14:08:02 Z mihai145 Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
1272 ms 640 KB
#include <iostream>

using namespace std;

/*
ifstream cin("txt.in");
ofstream cout("txt.out");
*/
  
const int INF = -1e9;

const int KMAX = 1000;
const int NMAX = 5000;

int K, N, M, A, B;
int dp[2][NMAX + 5][2][2];

int v[KMAX + 5], s[NMAX + 5], t[NMAX + 5];

void Upd(int i, int j, int x, int y)
{
    if(i < N && j < M && s[i + 1] == t[j + 1])
    {
        dp[!(i & 1)][j + 1][0][0] = max(dp[!(i & 1)][j + 1][0][0], dp[i & 1][j][x][y] + v[s[i + 1]]);
    }

    if(i < N)
    {
        dp[!(i & 1)][j][1][y] = max(dp[!(i & 1)][j][1][y], dp[i & 1][j][x][y] + B + ((x == 0) ? A : 0));
    }

    if(j < M)
    {
        dp[i & 1][j + 1][x][1] = max(dp[i & 1][j + 1][x][1], dp[i & 1][j][x][y] + B + ((y == 0) ? A : 0));
    }
}

int main()
{

    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 = 1; i <= M; i++)
        cin >> t[i];

    for(int j = 0; j <= M; j++)
        for(int x = 0; x < 2; x++)
            for(int y = 0; y < 2; y++)
                dp[0][j][x][y] = INF;

    dp[0][0][0][0] = 0;

    int res = A + M * B;

    for(int i = 0; i <= N; i++)
    {

        for(int j = 0; j <= M; j++)
            for(int x = 0; x < 2; x++)
                for(int y = 0; y < 2; y++)
                    dp[!(i & 1)][j][x][y] = INF;

        dp[!(i & 1)][0][0][0] = 0;

        for(int j = 0; j <= M; j++)
            for(int x = 0; x < 2; x++)
                for(int y = 0; y < 2; y++)
                    if(dp[i & 1][j][x][y] != INF)
                        Upd(i, j, x, y);

        for(int x = 0; x < 2; x++)
            for(int y = 0; y < 2; y++)
                res = max(res, dp[i & 1][M][x][y]);
    }

    cout << res << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 43 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 364 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 31 ms 364 KB Output is correct
10 Correct 53 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Correct 24 ms 364 KB Output is correct
7 Correct 25 ms 364 KB Output is correct
8 Correct 35 ms 364 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 52 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 364 KB Output is correct
2 Correct 33 ms 364 KB Output is correct
3 Correct 293 ms 492 KB Output is correct
4 Correct 677 ms 620 KB Output is correct
5 Correct 199 ms 492 KB Output is correct
6 Correct 288 ms 492 KB Output is correct
7 Correct 543 ms 620 KB Output is correct
8 Correct 175 ms 512 KB Output is correct
9 Correct 337 ms 492 KB Output is correct
10 Correct 845 ms 620 KB Output is correct
11 Correct 846 ms 620 KB Output is correct
12 Correct 843 ms 612 KB Output is correct
13 Correct 607 ms 620 KB Output is correct
14 Correct 1272 ms 592 KB Output is correct
15 Correct 1263 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 364 KB Output is correct
2 Correct 33 ms 364 KB Output is correct
3 Correct 293 ms 492 KB Output is correct
4 Correct 677 ms 620 KB Output is correct
5 Correct 199 ms 492 KB Output is correct
6 Correct 288 ms 492 KB Output is correct
7 Correct 543 ms 620 KB Output is correct
8 Correct 175 ms 512 KB Output is correct
9 Correct 337 ms 492 KB Output is correct
10 Correct 845 ms 620 KB Output is correct
11 Correct 846 ms 620 KB Output is correct
12 Correct 843 ms 612 KB Output is correct
13 Correct 607 ms 620 KB Output is correct
14 Correct 1272 ms 592 KB Output is correct
15 Correct 1263 ms 592 KB Output is correct
16 Correct 433 ms 620 KB Output is correct
17 Correct 548 ms 552 KB Output is correct
18 Correct 468 ms 492 KB Output is correct
19 Correct 99 ms 492 KB Output is correct
20 Correct 339 ms 620 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 106 ms 532 KB Output is correct
23 Correct 218 ms 492 KB Output is correct
24 Correct 76 ms 492 KB Output is correct
25 Correct 851 ms 612 KB Output is correct
26 Correct 843 ms 620 KB Output is correct
27 Correct 858 ms 620 KB Output is correct
28 Correct 627 ms 596 KB Output is correct
29 Correct 1225 ms 592 KB Output is correct
30 Correct 1229 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 364 KB Output is correct
2 Correct 33 ms 364 KB Output is correct
3 Correct 293 ms 492 KB Output is correct
4 Correct 677 ms 620 KB Output is correct
5 Correct 199 ms 492 KB Output is correct
6 Correct 288 ms 492 KB Output is correct
7 Correct 543 ms 620 KB Output is correct
8 Correct 175 ms 512 KB Output is correct
9 Correct 337 ms 492 KB Output is correct
10 Correct 845 ms 620 KB Output is correct
11 Correct 846 ms 620 KB Output is correct
12 Correct 843 ms 612 KB Output is correct
13 Correct 607 ms 620 KB Output is correct
14 Correct 1272 ms 592 KB Output is correct
15 Correct 1263 ms 592 KB Output is correct
16 Correct 726 ms 584 KB Output is correct
17 Correct 338 ms 492 KB Output is correct
18 Correct 98 ms 492 KB Output is correct
19 Correct 26 ms 512 KB Output is correct
20 Correct 11 ms 364 KB Output is correct
21 Correct 16 ms 492 KB Output is correct
22 Correct 323 ms 492 KB Output is correct
23 Correct 61 ms 492 KB Output is correct
24 Correct 581 ms 620 KB Output is correct
25 Correct 837 ms 616 KB Output is correct
26 Correct 859 ms 604 KB Output is correct
27 Correct 840 ms 612 KB Output is correct
28 Correct 591 ms 596 KB Output is correct
29 Correct 1240 ms 640 KB Output is correct
30 Correct 1235 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 43 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 364 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 31 ms 364 KB Output is correct
10 Correct 53 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 12 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 4 ms 364 KB Output is correct
16 Correct 24 ms 364 KB Output is correct
17 Correct 25 ms 364 KB Output is correct
18 Correct 35 ms 364 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 52 ms 364 KB Output is correct
21 Correct 83 ms 364 KB Output is correct
22 Correct 33 ms 364 KB Output is correct
23 Correct 293 ms 492 KB Output is correct
24 Correct 677 ms 620 KB Output is correct
25 Correct 199 ms 492 KB Output is correct
26 Correct 288 ms 492 KB Output is correct
27 Correct 543 ms 620 KB Output is correct
28 Correct 175 ms 512 KB Output is correct
29 Correct 337 ms 492 KB Output is correct
30 Correct 845 ms 620 KB Output is correct
31 Correct 846 ms 620 KB Output is correct
32 Correct 843 ms 612 KB Output is correct
33 Correct 607 ms 620 KB Output is correct
34 Correct 1272 ms 592 KB Output is correct
35 Correct 1263 ms 592 KB Output is correct
36 Correct 433 ms 620 KB Output is correct
37 Correct 548 ms 552 KB Output is correct
38 Correct 468 ms 492 KB Output is correct
39 Correct 99 ms 492 KB Output is correct
40 Correct 339 ms 620 KB Output is correct
41 Correct 19 ms 364 KB Output is correct
42 Correct 106 ms 532 KB Output is correct
43 Correct 218 ms 492 KB Output is correct
44 Correct 76 ms 492 KB Output is correct
45 Correct 851 ms 612 KB Output is correct
46 Correct 843 ms 620 KB Output is correct
47 Correct 858 ms 620 KB Output is correct
48 Correct 627 ms 596 KB Output is correct
49 Correct 1225 ms 592 KB Output is correct
50 Correct 1229 ms 592 KB Output is correct
51 Correct 726 ms 584 KB Output is correct
52 Correct 338 ms 492 KB Output is correct
53 Correct 98 ms 492 KB Output is correct
54 Correct 26 ms 512 KB Output is correct
55 Correct 11 ms 364 KB Output is correct
56 Correct 16 ms 492 KB Output is correct
57 Correct 323 ms 492 KB Output is correct
58 Correct 61 ms 492 KB Output is correct
59 Correct 581 ms 620 KB Output is correct
60 Correct 837 ms 616 KB Output is correct
61 Correct 859 ms 604 KB Output is correct
62 Correct 840 ms 612 KB Output is correct
63 Correct 591 ms 596 KB Output is correct
64 Correct 1240 ms 640 KB Output is correct
65 Correct 1235 ms 620 KB Output is correct
66 Correct 1 ms 396 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 364 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 1 ms 364 KB Output is correct
81 Correct 675 ms 592 KB Output is correct
82 Correct 154 ms 364 KB Output is correct
83 Correct 297 ms 492 KB Output is correct
84 Correct 167 ms 620 KB Output is correct
85 Correct 264 ms 492 KB Output is correct
86 Correct 226 ms 620 KB Output is correct
87 Correct 44 ms 364 KB Output is correct
88 Correct 25 ms 364 KB Output is correct
89 Correct 94 ms 364 KB Output is correct
90 Correct 942 ms 620 KB Output is correct
91 Correct 853 ms 620 KB Output is correct
92 Correct 843 ms 620 KB Output is correct
93 Correct 844 ms 612 KB Output is correct
94 Correct 849 ms 620 KB Output is correct
95 Correct 588 ms 620 KB Output is correct
96 Correct 848 ms 620 KB Output is correct
97 Correct 844 ms 604 KB Output is correct
98 Correct 1221 ms 620 KB Output is correct
99 Correct 1235 ms 620 KB Output is correct
100 Correct 1224 ms 620 KB Output is correct