# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
233979 | 2020-05-22T14:57:46 Z | WannnabeIOI | Visiting Singapore (NOI20_visitingsingapore) | C++14 | 183 ms | 760 KB |
#include <bits/stdc++.h> using namespace std; const int mn = -2e9; int K, M, N, A, B; int V[1005], S[5005], T[5005]; int dp[5][5005][5]; int main() { ios_base::sync_with_stdio(false); cin.tie (NULL); cout.tie (NULL); // freopen("inp", "r", stdin); scanf("%d %d %d %d %d", &K, &N, &M, &A, &B); for(int i = 1; i <= K; i++) scanf("%d", &V[i]); for(int i = 1; i <= N; i++) scanf("%d", &S[i]); for(int i = 1; i <= M; i++) scanf("%d", &T[i]); for(int i = 0; i <= M; i++) { for(int j = 1; j <= 4; j++) { dp[0][i][j] = mn; } } int ans = A + M * B; for(int i = 1; i <= N; i++) { int now = i % 2, bef = !now; for(int k = 1; k <= 4; k++) dp[now][0][k] = mn; for(int j = 1; j <= M; j++) { if(S[i] == T[j]) { int opt = (j == 1 ? 0 : (A + (j - 1) * B)); for(int k = 1; k <= 4; k++) { opt = max(opt, dp[bef][j - 1][k]); } dp[now][j][4] = opt + V[S[i]]; }else { dp[now][j][4] = mn; } //if you don't take T[j - 1] beforehand dp[now][j][2] = max(dp[now][j - 1][2] + B, dp[now][j - 1][4] + A + B); dp[now][j][3] = max(dp[bef][j][3] + B, dp[bef][j][4] + A + B); dp[now][j][1] = max(dp[now][j - 1][3] + A + B, max(dp[now][j - 1][1] + B, 2*A + (j + 1)*B)); } for(int k = 1; k <= 4; k++) { // cout << i << " " << k << " " << dp[now][M][k] << "\n"; ans = max(ans, dp[now][M][k]); } } printf("%d\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 11 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 8 ms | 384 KB | Output is correct |
10 | Correct | 12 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 7 ms | 384 KB | Output is correct |
6 | Correct | 8 ms | 384 KB | Output is correct |
7 | Correct | 9 ms | 384 KB | Output is correct |
8 | Correct | 10 ms | 384 KB | Output is correct |
9 | Correct | 6 ms | 384 KB | Output is correct |
10 | Correct | 12 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 512 KB | Output is correct |
2 | Correct | 10 ms | 384 KB | Output is correct |
3 | Correct | 49 ms | 512 KB | Output is correct |
4 | Correct | 114 ms | 640 KB | Output is correct |
5 | Correct | 37 ms | 640 KB | Output is correct |
6 | Correct | 51 ms | 512 KB | Output is correct |
7 | Correct | 91 ms | 512 KB | Output is correct |
8 | Correct | 34 ms | 512 KB | Output is correct |
9 | Correct | 59 ms | 512 KB | Output is correct |
10 | Correct | 140 ms | 640 KB | Output is correct |
11 | Correct | 142 ms | 760 KB | Output is correct |
12 | Correct | 143 ms | 640 KB | Output is correct |
13 | Correct | 138 ms | 640 KB | Output is correct |
14 | Correct | 179 ms | 640 KB | Output is correct |
15 | Correct | 179 ms | 760 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 512 KB | Output is correct |
2 | Correct | 10 ms | 384 KB | Output is correct |
3 | Correct | 49 ms | 512 KB | Output is correct |
4 | Correct | 114 ms | 640 KB | Output is correct |
5 | Correct | 37 ms | 640 KB | Output is correct |
6 | Correct | 51 ms | 512 KB | Output is correct |
7 | Correct | 91 ms | 512 KB | Output is correct |
8 | Correct | 34 ms | 512 KB | Output is correct |
9 | Correct | 59 ms | 512 KB | Output is correct |
10 | Correct | 140 ms | 640 KB | Output is correct |
11 | Correct | 142 ms | 760 KB | Output is correct |
12 | Correct | 143 ms | 640 KB | Output is correct |
13 | Correct | 138 ms | 640 KB | Output is correct |
14 | Correct | 179 ms | 640 KB | Output is correct |
15 | Correct | 179 ms | 760 KB | Output is correct |
16 | Correct | 75 ms | 632 KB | Output is correct |
17 | Correct | 90 ms | 512 KB | Output is correct |
18 | Correct | 81 ms | 512 KB | Output is correct |
19 | Correct | 20 ms | 512 KB | Output is correct |
20 | Correct | 58 ms | 512 KB | Output is correct |
21 | Correct | 8 ms | 384 KB | Output is correct |
22 | Correct | 22 ms | 512 KB | Output is correct |
23 | Correct | 38 ms | 512 KB | Output is correct |
24 | Correct | 17 ms | 384 KB | Output is correct |
25 | Correct | 140 ms | 640 KB | Output is correct |
26 | Correct | 139 ms | 760 KB | Output is correct |
27 | Correct | 140 ms | 640 KB | Output is correct |
28 | Correct | 139 ms | 640 KB | Output is correct |
29 | Correct | 176 ms | 640 KB | Output is correct |
30 | Correct | 178 ms | 760 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 512 KB | Output is correct |
2 | Correct | 10 ms | 384 KB | Output is correct |
3 | Correct | 49 ms | 512 KB | Output is correct |
4 | Correct | 114 ms | 640 KB | Output is correct |
5 | Correct | 37 ms | 640 KB | Output is correct |
6 | Correct | 51 ms | 512 KB | Output is correct |
7 | Correct | 91 ms | 512 KB | Output is correct |
8 | Correct | 34 ms | 512 KB | Output is correct |
9 | Correct | 59 ms | 512 KB | Output is correct |
10 | Correct | 140 ms | 640 KB | Output is correct |
11 | Correct | 142 ms | 760 KB | Output is correct |
12 | Correct | 143 ms | 640 KB | Output is correct |
13 | Correct | 138 ms | 640 KB | Output is correct |
14 | Correct | 179 ms | 640 KB | Output is correct |
15 | Correct | 179 ms | 760 KB | Output is correct |
16 | Correct | 118 ms | 632 KB | Output is correct |
17 | Correct | 58 ms | 512 KB | Output is correct |
18 | Correct | 21 ms | 640 KB | Output is correct |
19 | Correct | 9 ms | 384 KB | Output is correct |
20 | Correct | 7 ms | 512 KB | Output is correct |
21 | Correct | 8 ms | 512 KB | Output is correct |
22 | Correct | 57 ms | 512 KB | Output is correct |
23 | Correct | 15 ms | 384 KB | Output is correct |
24 | Correct | 98 ms | 512 KB | Output is correct |
25 | Correct | 140 ms | 640 KB | Output is correct |
26 | Correct | 143 ms | 640 KB | Output is correct |
27 | Correct | 141 ms | 664 KB | Output is correct |
28 | Correct | 139 ms | 640 KB | Output is correct |
29 | Correct | 178 ms | 640 KB | Output is correct |
30 | Correct | 182 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 11 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 8 ms | 384 KB | Output is correct |
10 | Correct | 12 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 6 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 7 ms | 384 KB | Output is correct |
16 | Correct | 8 ms | 384 KB | Output is correct |
17 | Correct | 9 ms | 384 KB | Output is correct |
18 | Correct | 10 ms | 384 KB | Output is correct |
19 | Correct | 6 ms | 384 KB | Output is correct |
20 | Correct | 12 ms | 384 KB | Output is correct |
21 | Correct | 18 ms | 512 KB | Output is correct |
22 | Correct | 10 ms | 384 KB | Output is correct |
23 | Correct | 49 ms | 512 KB | Output is correct |
24 | Correct | 114 ms | 640 KB | Output is correct |
25 | Correct | 37 ms | 640 KB | Output is correct |
26 | Correct | 51 ms | 512 KB | Output is correct |
27 | Correct | 91 ms | 512 KB | Output is correct |
28 | Correct | 34 ms | 512 KB | Output is correct |
29 | Correct | 59 ms | 512 KB | Output is correct |
30 | Correct | 140 ms | 640 KB | Output is correct |
31 | Correct | 142 ms | 760 KB | Output is correct |
32 | Correct | 143 ms | 640 KB | Output is correct |
33 | Correct | 138 ms | 640 KB | Output is correct |
34 | Correct | 179 ms | 640 KB | Output is correct |
35 | Correct | 179 ms | 760 KB | Output is correct |
36 | Correct | 75 ms | 632 KB | Output is correct |
37 | Correct | 90 ms | 512 KB | Output is correct |
38 | Correct | 81 ms | 512 KB | Output is correct |
39 | Correct | 20 ms | 512 KB | Output is correct |
40 | Correct | 58 ms | 512 KB | Output is correct |
41 | Correct | 8 ms | 384 KB | Output is correct |
42 | Correct | 22 ms | 512 KB | Output is correct |
43 | Correct | 38 ms | 512 KB | Output is correct |
44 | Correct | 17 ms | 384 KB | Output is correct |
45 | Correct | 140 ms | 640 KB | Output is correct |
46 | Correct | 139 ms | 760 KB | Output is correct |
47 | Correct | 140 ms | 640 KB | Output is correct |
48 | Correct | 139 ms | 640 KB | Output is correct |
49 | Correct | 176 ms | 640 KB | Output is correct |
50 | Correct | 178 ms | 760 KB | Output is correct |
51 | Correct | 118 ms | 632 KB | Output is correct |
52 | Correct | 58 ms | 512 KB | Output is correct |
53 | Correct | 21 ms | 640 KB | Output is correct |
54 | Correct | 9 ms | 384 KB | Output is correct |
55 | Correct | 7 ms | 512 KB | Output is correct |
56 | Correct | 8 ms | 512 KB | Output is correct |
57 | Correct | 57 ms | 512 KB | Output is correct |
58 | Correct | 15 ms | 384 KB | Output is correct |
59 | Correct | 98 ms | 512 KB | Output is correct |
60 | Correct | 140 ms | 640 KB | Output is correct |
61 | Correct | 143 ms | 640 KB | Output is correct |
62 | Correct | 141 ms | 664 KB | Output is correct |
63 | Correct | 139 ms | 640 KB | Output is correct |
64 | Correct | 178 ms | 640 KB | Output is correct |
65 | Correct | 182 ms | 640 KB | Output is correct |
66 | Correct | 5 ms | 384 KB | Output is correct |
67 | Correct | 4 ms | 384 KB | Output is correct |
68 | Correct | 5 ms | 384 KB | Output is correct |
69 | Correct | 5 ms | 384 KB | Output is correct |
70 | Correct | 5 ms | 384 KB | Output is correct |
71 | Correct | 5 ms | 512 KB | Output is correct |
72 | Correct | 5 ms | 384 KB | Output is correct |
73 | Correct | 5 ms | 384 KB | Output is correct |
74 | Correct | 5 ms | 384 KB | Output is correct |
75 | Correct | 5 ms | 384 KB | Output is correct |
76 | Correct | 5 ms | 384 KB | Output is correct |
77 | Correct | 5 ms | 384 KB | Output is correct |
78 | Correct | 5 ms | 384 KB | Output is correct |
79 | Correct | 5 ms | 384 KB | Output is correct |
80 | Correct | 5 ms | 384 KB | Output is correct |
81 | Correct | 115 ms | 632 KB | Output is correct |
82 | Correct | 30 ms | 512 KB | Output is correct |
83 | Correct | 52 ms | 512 KB | Output is correct |
84 | Correct | 31 ms | 512 KB | Output is correct |
85 | Correct | 48 ms | 512 KB | Output is correct |
86 | Correct | 41 ms | 512 KB | Output is correct |
87 | Correct | 11 ms | 416 KB | Output is correct |
88 | Correct | 9 ms | 384 KB | Output is correct |
89 | Correct | 20 ms | 512 KB | Output is correct |
90 | Correct | 156 ms | 640 KB | Output is correct |
91 | Correct | 139 ms | 640 KB | Output is correct |
92 | Correct | 142 ms | 640 KB | Output is correct |
93 | Correct | 139 ms | 640 KB | Output is correct |
94 | Correct | 142 ms | 640 KB | Output is correct |
95 | Correct | 140 ms | 640 KB | Output is correct |
96 | Correct | 143 ms | 640 KB | Output is correct |
97 | Correct | 144 ms | 640 KB | Output is correct |
98 | Correct | 180 ms | 760 KB | Output is correct |
99 | Correct | 183 ms | 640 KB | Output is correct |
100 | Correct | 179 ms | 640 KB | Output is correct |