Submission #259073

# Submission time Handle Problem Language Result Execution time Memory
259073 2020-08-07T06:50:23 Z ryangohca Visiting Singapore (NOI20_visitingsingapore) C++17
100 / 100
850 ms 888 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int places[5001];
vector<int> happy;
vector<int> favourites;
int n, m, a, b;
int memo[2][5001][2][2];
main(){
	int k; cin >> k >> n >> m >> a >> b;
	happy.push_back(0);
	for (int i = 0; i < k; i++){
		int g; cin >> g;
		happy.push_back(g);
	}
	for (int i = 0; i < n; i++){
		cin >> places[i];
	}
	for (int i = 0; i < m; i++){
		int g; cin >> g;
		favourites.push_back(g);
	}
	int ans = a + m * b;
	int idx = 0;
	for (int i = 10000; i >= 0; i--){
		for (int j = m - 1; j >= 0; j--){
			for (int st = false; st <= true; st++){
				for (int sf = false; sf <= true; sf++){
					int ans = a + (m - j) * b;
					if (!st) ans = max(ans, memo[1 - idx][j][true][false] + a + b);
					else ans = max(ans, memo[1 - idx][j][true][false] + b);
					if (!sf) ans = max(ans, memo[idx][j + 1][false][true] + a + b);
					else ans = max(ans, memo[idx][j + 1][false][true] + b);
					if (i < n && places[i] == favourites[j]) ans = max(ans, memo[1-idx][j+1][false][false] + happy[places[i]]);
					memo[idx][j][st][sf] = ans;
				}
			}
		}
		if (i < n)ans = max(ans, memo[idx][0][false][false]);
		idx = 1 - idx;
	}
	cout << ans << endl;
}

Compilation message

VisitingSingapore.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 117 ms 384 KB Output is correct
3 Correct 13 ms 384 KB Output is correct
4 Correct 10 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 39 ms 384 KB Output is correct
7 Correct 10 ms 384 KB Output is correct
8 Correct 21 ms 384 KB Output is correct
9 Correct 87 ms 504 KB Output is correct
10 Correct 133 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 512 KB Output is correct
2 Correct 49 ms 384 KB Output is correct
3 Correct 97 ms 448 KB Output is correct
4 Correct 24 ms 384 KB Output is correct
5 Correct 57 ms 504 KB Output is correct
6 Correct 105 ms 384 KB Output is correct
7 Correct 115 ms 384 KB Output is correct
8 Correct 111 ms 504 KB Output is correct
9 Correct 41 ms 384 KB Output is correct
10 Correct 131 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 384 KB Output is correct
2 Correct 58 ms 384 KB Output is correct
3 Correct 327 ms 624 KB Output is correct
4 Correct 688 ms 888 KB Output is correct
5 Correct 542 ms 760 KB Output is correct
6 Correct 487 ms 640 KB Output is correct
7 Correct 512 ms 760 KB Output is correct
8 Correct 219 ms 632 KB Output is correct
9 Correct 490 ms 760 KB Output is correct
10 Correct 786 ms 868 KB Output is correct
11 Correct 799 ms 768 KB Output is correct
12 Correct 850 ms 888 KB Output is correct
13 Correct 835 ms 852 KB Output is correct
14 Correct 773 ms 768 KB Output is correct
15 Correct 735 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 384 KB Output is correct
2 Correct 58 ms 384 KB Output is correct
3 Correct 327 ms 624 KB Output is correct
4 Correct 688 ms 888 KB Output is correct
5 Correct 542 ms 760 KB Output is correct
6 Correct 487 ms 640 KB Output is correct
7 Correct 512 ms 760 KB Output is correct
8 Correct 219 ms 632 KB Output is correct
9 Correct 490 ms 760 KB Output is correct
10 Correct 786 ms 868 KB Output is correct
11 Correct 799 ms 768 KB Output is correct
12 Correct 850 ms 888 KB Output is correct
13 Correct 835 ms 852 KB Output is correct
14 Correct 773 ms 768 KB Output is correct
15 Correct 735 ms 844 KB Output is correct
16 Correct 510 ms 640 KB Output is correct
17 Correct 520 ms 760 KB Output is correct
18 Correct 461 ms 696 KB Output is correct
19 Correct 350 ms 640 KB Output is correct
20 Correct 394 ms 648 KB Output is correct
21 Correct 57 ms 384 KB Output is correct
22 Correct 473 ms 684 KB Output is correct
23 Correct 469 ms 760 KB Output is correct
24 Correct 137 ms 492 KB Output is correct
25 Correct 774 ms 864 KB Output is correct
26 Correct 844 ms 864 KB Output is correct
27 Correct 796 ms 888 KB Output is correct
28 Correct 799 ms 888 KB Output is correct
29 Correct 740 ms 844 KB Output is correct
30 Correct 740 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 384 KB Output is correct
2 Correct 58 ms 384 KB Output is correct
3 Correct 327 ms 624 KB Output is correct
4 Correct 688 ms 888 KB Output is correct
5 Correct 542 ms 760 KB Output is correct
6 Correct 487 ms 640 KB Output is correct
7 Correct 512 ms 760 KB Output is correct
8 Correct 219 ms 632 KB Output is correct
9 Correct 490 ms 760 KB Output is correct
10 Correct 786 ms 868 KB Output is correct
11 Correct 799 ms 768 KB Output is correct
12 Correct 850 ms 888 KB Output is correct
13 Correct 835 ms 852 KB Output is correct
14 Correct 773 ms 768 KB Output is correct
15 Correct 735 ms 844 KB Output is correct
16 Correct 661 ms 768 KB Output is correct
17 Correct 328 ms 512 KB Output is correct
18 Correct 312 ms 616 KB Output is correct
19 Correct 87 ms 384 KB Output is correct
20 Correct 210 ms 512 KB Output is correct
21 Correct 679 ms 888 KB Output is correct
22 Correct 511 ms 640 KB Output is correct
23 Correct 136 ms 384 KB Output is correct
24 Correct 544 ms 640 KB Output is correct
25 Correct 753 ms 888 KB Output is correct
26 Correct 779 ms 888 KB Output is correct
27 Correct 787 ms 864 KB Output is correct
28 Correct 762 ms 852 KB Output is correct
29 Correct 708 ms 888 KB Output is correct
30 Correct 708 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 10 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 14 ms 384 KB Output is correct
10 Correct 13 ms 384 KB Output is correct
11 Correct 14 ms 384 KB Output is correct
12 Correct 13 ms 384 KB Output is correct
13 Correct 14 ms 384 KB Output is correct
14 Correct 14 ms 384 KB Output is correct
15 Correct 13 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 117 ms 384 KB Output is correct
3 Correct 13 ms 384 KB Output is correct
4 Correct 10 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 39 ms 384 KB Output is correct
7 Correct 10 ms 384 KB Output is correct
8 Correct 21 ms 384 KB Output is correct
9 Correct 87 ms 504 KB Output is correct
10 Correct 133 ms 468 KB Output is correct
11 Correct 109 ms 512 KB Output is correct
12 Correct 49 ms 384 KB Output is correct
13 Correct 97 ms 448 KB Output is correct
14 Correct 24 ms 384 KB Output is correct
15 Correct 57 ms 504 KB Output is correct
16 Correct 105 ms 384 KB Output is correct
17 Correct 115 ms 384 KB Output is correct
18 Correct 111 ms 504 KB Output is correct
19 Correct 41 ms 384 KB Output is correct
20 Correct 131 ms 384 KB Output is correct
21 Correct 139 ms 384 KB Output is correct
22 Correct 58 ms 384 KB Output is correct
23 Correct 327 ms 624 KB Output is correct
24 Correct 688 ms 888 KB Output is correct
25 Correct 542 ms 760 KB Output is correct
26 Correct 487 ms 640 KB Output is correct
27 Correct 512 ms 760 KB Output is correct
28 Correct 219 ms 632 KB Output is correct
29 Correct 490 ms 760 KB Output is correct
30 Correct 786 ms 868 KB Output is correct
31 Correct 799 ms 768 KB Output is correct
32 Correct 850 ms 888 KB Output is correct
33 Correct 835 ms 852 KB Output is correct
34 Correct 773 ms 768 KB Output is correct
35 Correct 735 ms 844 KB Output is correct
36 Correct 510 ms 640 KB Output is correct
37 Correct 520 ms 760 KB Output is correct
38 Correct 461 ms 696 KB Output is correct
39 Correct 350 ms 640 KB Output is correct
40 Correct 394 ms 648 KB Output is correct
41 Correct 57 ms 384 KB Output is correct
42 Correct 473 ms 684 KB Output is correct
43 Correct 469 ms 760 KB Output is correct
44 Correct 137 ms 492 KB Output is correct
45 Correct 774 ms 864 KB Output is correct
46 Correct 844 ms 864 KB Output is correct
47 Correct 796 ms 888 KB Output is correct
48 Correct 799 ms 888 KB Output is correct
49 Correct 740 ms 844 KB Output is correct
50 Correct 740 ms 888 KB Output is correct
51 Correct 661 ms 768 KB Output is correct
52 Correct 328 ms 512 KB Output is correct
53 Correct 312 ms 616 KB Output is correct
54 Correct 87 ms 384 KB Output is correct
55 Correct 210 ms 512 KB Output is correct
56 Correct 679 ms 888 KB Output is correct
57 Correct 511 ms 640 KB Output is correct
58 Correct 136 ms 384 KB Output is correct
59 Correct 544 ms 640 KB Output is correct
60 Correct 753 ms 888 KB Output is correct
61 Correct 779 ms 888 KB Output is correct
62 Correct 787 ms 864 KB Output is correct
63 Correct 762 ms 852 KB Output is correct
64 Correct 708 ms 888 KB Output is correct
65 Correct 708 ms 888 KB Output is correct
66 Correct 6 ms 384 KB Output is correct
67 Correct 5 ms 512 KB Output is correct
68 Correct 3 ms 384 KB Output is correct
69 Correct 7 ms 384 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
71 Correct 10 ms 384 KB Output is correct
72 Correct 4 ms 384 KB Output is correct
73 Correct 3 ms 384 KB Output is correct
74 Correct 14 ms 384 KB Output is correct
75 Correct 13 ms 384 KB Output is correct
76 Correct 14 ms 384 KB Output is correct
77 Correct 13 ms 384 KB Output is correct
78 Correct 14 ms 384 KB Output is correct
79 Correct 14 ms 384 KB Output is correct
80 Correct 13 ms 308 KB Output is correct
81 Correct 620 ms 812 KB Output is correct
82 Correct 233 ms 512 KB Output is correct
83 Correct 506 ms 888 KB Output is correct
84 Correct 453 ms 640 KB Output is correct
85 Correct 393 ms 760 KB Output is correct
86 Correct 293 ms 512 KB Output is correct
87 Correct 173 ms 512 KB Output is correct
88 Correct 82 ms 504 KB Output is correct
89 Correct 228 ms 512 KB Output is correct
90 Correct 806 ms 888 KB Output is correct
91 Correct 776 ms 860 KB Output is correct
92 Correct 775 ms 768 KB Output is correct
93 Correct 765 ms 768 KB Output is correct
94 Correct 777 ms 888 KB Output is correct
95 Correct 767 ms 844 KB Output is correct
96 Correct 787 ms 856 KB Output is correct
97 Correct 769 ms 856 KB Output is correct
98 Correct 747 ms 768 KB Output is correct
99 Correct 716 ms 768 KB Output is correct
100 Correct 738 ms 768 KB Output is correct