답안 #224552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224552 2020-04-18T11:51:23 Z Nightlight Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
181 ms 768 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() {
//  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;
    }
  }
  //kalau ga terbang
  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;
      }
      //jika ga ambil T[j - 1] sebelumnya
      dp[now][j][2] = max(dp[now][j - 1][2] + B, dp[now][j - 1][4] + A + B);
      //jika ga ambil S[i - 1] sebelumnya
      dp[now][j][3] = max(dp[bef][j][3] + B, dp[bef][j][4] + A + B);
      //jika ga keduanya
      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

VisitingSingapore.cpp: In function 'int main()':
VisitingSingapore.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d %d", &K, &N, &M, &A, &B);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VisitingSingapore.cpp:13:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= K; i++) scanf("%d", &V[i]);
                               ~~~~~^~~~~~~~~~~~~
VisitingSingapore.cpp:14:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= N; i++) scanf("%d", &S[i]);
                               ~~~~~^~~~~~~~~~~~~
VisitingSingapore.cpp:15:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= M; i++) scanf("%d", &T[i]);
                               ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 10 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 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 9 ms 512 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 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 9 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 11 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 49 ms 512 KB Output is correct
4 Correct 113 ms 640 KB Output is correct
5 Correct 36 ms 512 KB Output is correct
6 Correct 51 ms 512 KB Output is correct
7 Correct 91 ms 572 KB Output is correct
8 Correct 33 ms 384 KB Output is correct
9 Correct 62 ms 512 KB Output is correct
10 Correct 138 ms 640 KB Output is correct
11 Correct 137 ms 640 KB Output is correct
12 Correct 140 ms 640 KB Output is correct
13 Correct 138 ms 632 KB Output is correct
14 Correct 176 ms 632 KB Output is correct
15 Correct 175 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 49 ms 512 KB Output is correct
4 Correct 113 ms 640 KB Output is correct
5 Correct 36 ms 512 KB Output is correct
6 Correct 51 ms 512 KB Output is correct
7 Correct 91 ms 572 KB Output is correct
8 Correct 33 ms 384 KB Output is correct
9 Correct 62 ms 512 KB Output is correct
10 Correct 138 ms 640 KB Output is correct
11 Correct 137 ms 640 KB Output is correct
12 Correct 140 ms 640 KB Output is correct
13 Correct 138 ms 632 KB Output is correct
14 Correct 176 ms 632 KB Output is correct
15 Correct 175 ms 640 KB Output is correct
16 Correct 75 ms 512 KB Output is correct
17 Correct 89 ms 512 KB Output is correct
18 Correct 79 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 141 ms 768 KB Output is correct
26 Correct 141 ms 640 KB Output is correct
27 Correct 138 ms 636 KB Output is correct
28 Correct 137 ms 632 KB Output is correct
29 Correct 179 ms 512 KB Output is correct
30 Correct 174 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 49 ms 512 KB Output is correct
4 Correct 113 ms 640 KB Output is correct
5 Correct 36 ms 512 KB Output is correct
6 Correct 51 ms 512 KB Output is correct
7 Correct 91 ms 572 KB Output is correct
8 Correct 33 ms 384 KB Output is correct
9 Correct 62 ms 512 KB Output is correct
10 Correct 138 ms 640 KB Output is correct
11 Correct 137 ms 640 KB Output is correct
12 Correct 140 ms 640 KB Output is correct
13 Correct 138 ms 632 KB Output is correct
14 Correct 176 ms 632 KB Output is correct
15 Correct 175 ms 640 KB Output is correct
16 Correct 116 ms 512 KB Output is correct
17 Correct 58 ms 512 KB Output is correct
18 Correct 21 ms 512 KB Output is correct
19 Correct 9 ms 384 KB Output is correct
20 Correct 7 ms 384 KB Output is correct
21 Correct 8 ms 512 KB Output is correct
22 Correct 57 ms 512 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 96 ms 512 KB Output is correct
25 Correct 140 ms 640 KB Output is correct
26 Correct 140 ms 640 KB Output is correct
27 Correct 138 ms 640 KB Output is correct
28 Correct 137 ms 512 KB Output is correct
29 Correct 175 ms 760 KB Output is correct
30 Correct 176 ms 512 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 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 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 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 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 384 KB Output is correct
2 Correct 10 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 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 9 ms 512 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 5 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 9 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 11 ms 384 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 10 ms 384 KB Output is correct
23 Correct 49 ms 512 KB Output is correct
24 Correct 113 ms 640 KB Output is correct
25 Correct 36 ms 512 KB Output is correct
26 Correct 51 ms 512 KB Output is correct
27 Correct 91 ms 572 KB Output is correct
28 Correct 33 ms 384 KB Output is correct
29 Correct 62 ms 512 KB Output is correct
30 Correct 138 ms 640 KB Output is correct
31 Correct 137 ms 640 KB Output is correct
32 Correct 140 ms 640 KB Output is correct
33 Correct 138 ms 632 KB Output is correct
34 Correct 176 ms 632 KB Output is correct
35 Correct 175 ms 640 KB Output is correct
36 Correct 75 ms 512 KB Output is correct
37 Correct 89 ms 512 KB Output is correct
38 Correct 79 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 141 ms 768 KB Output is correct
46 Correct 141 ms 640 KB Output is correct
47 Correct 138 ms 636 KB Output is correct
48 Correct 137 ms 632 KB Output is correct
49 Correct 179 ms 512 KB Output is correct
50 Correct 174 ms 512 KB Output is correct
51 Correct 116 ms 512 KB Output is correct
52 Correct 58 ms 512 KB Output is correct
53 Correct 21 ms 512 KB Output is correct
54 Correct 9 ms 384 KB Output is correct
55 Correct 7 ms 384 KB Output is correct
56 Correct 8 ms 512 KB Output is correct
57 Correct 57 ms 512 KB Output is correct
58 Correct 14 ms 384 KB Output is correct
59 Correct 96 ms 512 KB Output is correct
60 Correct 140 ms 640 KB Output is correct
61 Correct 140 ms 640 KB Output is correct
62 Correct 138 ms 640 KB Output is correct
63 Correct 137 ms 512 KB Output is correct
64 Correct 175 ms 760 KB Output is correct
65 Correct 176 ms 512 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 4 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 4 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 4 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 4 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 117 ms 512 KB Output is correct
82 Correct 31 ms 384 KB Output is correct
83 Correct 53 ms 604 KB Output is correct
84 Correct 31 ms 512 KB Output is correct
85 Correct 48 ms 512 KB Output is correct
86 Correct 42 ms 508 KB Output is correct
87 Correct 13 ms 512 KB Output is correct
88 Correct 8 ms 384 KB Output is correct
89 Correct 20 ms 384 KB Output is correct
90 Correct 160 ms 656 KB Output is correct
91 Correct 138 ms 640 KB Output is correct
92 Correct 139 ms 640 KB Output is correct
93 Correct 145 ms 640 KB Output is correct
94 Correct 143 ms 632 KB Output is correct
95 Correct 138 ms 512 KB Output is correct
96 Correct 148 ms 632 KB Output is correct
97 Correct 145 ms 640 KB Output is correct
98 Correct 175 ms 512 KB Output is correct
99 Correct 181 ms 512 KB Output is correct
100 Correct 180 ms 512 KB Output is correct