//#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 500;
vector<ll> col[maxn];
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
//两个情况:用i-1行还是不用
for (int i = 0; i < m; i++) col[x[i]].push_back(i);
for (int i = 0; i < n; i++) {
sort(col[i].begin(), col[i].end(), [&](int i, int j) {
return y[i] < y[j];
});
}
vector<ll> up_max(n), down_max(n), up(m), down(m);
//up_max表示最高能拿多少,down_max相似
//up[i] 还表示若做墙壁在第i个点最高能拿多少,down[i]相似
for (int i = 0; i < n; i++) {
if (col[i].size() == 0) {
if (i == 0) up_max[i] = down_max[i] = 0;
else up_max[i] = up_max[i - 1], down_max[i] = down_max[i - 1];
continue;
}
//第一种情况:假装删除第i-1行来做
ll mx = (i < 2 ? 0LL : max(up_max[i - 2], down_max[i - 1]));
for (int j = 0; j < col[i].size(); j++) {
int now = col[i][j];
if (j == 0) up[now] = mx + w[now];
else up[now] = up[col[i][j-1]] + w[now];
}
if (i > 0) {
mx = (i < 2 ? 0LL : max(up_max[i - 2], down_max[i - 2]));
for (int j = col[i].size() - 1; j >= 0; j--) {
int now = col[i][j], above = (j < col[i].size() - 1 ? col[i][j + 1]: -1);
if (above==-1) down[now] = mx + w[now];
else down[now] = down[above] + w[now];
}
}
//第二种:利用i-1行做墙壁
if (i > 0 && col[i-1].size()) {
int p = -1;
for (int j = 0; j < col[i].size(); j++) {
int now = col[i][j], below = (j >= 1 ? col[i][j - 1] : -1), x = col[i - 1].size();
while (p<x-1 && y[col[i - 1][p + 1]] < y[now]) p++;
if (p == -1) continue;
if (below == -1) up[now] = max(up[now], up[col[i - 1][p]] + w[now]);
else up[now] = max(up[now], max(up[below], up[col[i - 1][p]]) + w[now]);
}
p = col[i - 1].size();
for (int j = col[i].size() - 1; j >= 0; j--) {
int now = col[i][j], above = (j < col[i].size() - 1 ? col[i][j + 1] : -1);
while (p > 0 && y[col[i - 1][p - 1]] > y[now]) p--;
if (p == col[i-1].size()) continue;
if (above == -1) down[now] = max(down[now], down[col[i - 1][p]] + w[now]);
else down[now] = max(down[now], max(down[above], down[col[i - 1][p]]) + w[now]);
}
}
if (i == 0) {
up_max[i] = up[col[i][col[i].size() - 1]];
down_max[i] = down[col[i][0]];
}
else {
up_max[i] = max(up_max[i-1],up[col[i][col[i].size() - 1]]);
down_max[i] = max(down_max[i-1],down[col[i][0]]);
}
}
return max(down_max[n - 1], up_max[n - 2]);
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int j = 0; j < col[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:34:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | int now = col[i][j], above = (j < col[i].size() - 1 ? col[i][j + 1]: -1);
| ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = 0; j < col[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:51:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | int now = col[i][j], above = (j < col[i].size() - 1 ? col[i][j + 1] : -1);
| ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:53:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if (p == col[i-1].size()) continue;
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
7892 KB |
Output is correct |
2 |
Correct |
33 ms |
8948 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
99 ms |
18556 KB |
Output is correct |
6 |
Correct |
104 ms |
20260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
55 ms |
11748 KB |
Output is correct |
3 |
Correct |
66 ms |
13768 KB |
Output is correct |
4 |
Correct |
27 ms |
8008 KB |
Output is correct |
5 |
Correct |
36 ms |
8996 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
27 ms |
7964 KB |
Output is correct |
13 |
Correct |
33 ms |
9032 KB |
Output is correct |
14 |
Correct |
27 ms |
7984 KB |
Output is correct |
15 |
Correct |
31 ms |
8716 KB |
Output is correct |
16 |
Correct |
28 ms |
8100 KB |
Output is correct |
17 |
Correct |
30 ms |
8576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
18 ms |
7784 KB |
Output is correct |
4 |
Correct |
13 ms |
6672 KB |
Output is correct |
5 |
Correct |
34 ms |
11268 KB |
Output is correct |
6 |
Correct |
30 ms |
11264 KB |
Output is correct |
7 |
Correct |
33 ms |
11272 KB |
Output is correct |
8 |
Correct |
34 ms |
11256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
14 ms |
4868 KB |
Output is correct |
18 |
Correct |
14 ms |
5120 KB |
Output is correct |
19 |
Correct |
14 ms |
5128 KB |
Output is correct |
20 |
Correct |
14 ms |
5096 KB |
Output is correct |
21 |
Correct |
15 ms |
5116 KB |
Output is correct |
22 |
Correct |
26 ms |
7596 KB |
Output is correct |
23 |
Correct |
4 ms |
3028 KB |
Output is correct |
24 |
Correct |
10 ms |
4164 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
4 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
14 ms |
4868 KB |
Output is correct |
18 |
Correct |
14 ms |
5120 KB |
Output is correct |
19 |
Correct |
14 ms |
5128 KB |
Output is correct |
20 |
Correct |
14 ms |
5096 KB |
Output is correct |
21 |
Correct |
15 ms |
5116 KB |
Output is correct |
22 |
Correct |
26 ms |
7596 KB |
Output is correct |
23 |
Correct |
4 ms |
3028 KB |
Output is correct |
24 |
Correct |
10 ms |
4164 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
4 ms |
3028 KB |
Output is correct |
27 |
Correct |
2 ms |
2900 KB |
Output is correct |
28 |
Correct |
68 ms |
14324 KB |
Output is correct |
29 |
Correct |
97 ms |
18168 KB |
Output is correct |
30 |
Correct |
95 ms |
17820 KB |
Output is correct |
31 |
Correct |
96 ms |
17824 KB |
Output is correct |
32 |
Correct |
89 ms |
19244 KB |
Output is correct |
33 |
Correct |
98 ms |
17836 KB |
Output is correct |
34 |
Correct |
96 ms |
17824 KB |
Output is correct |
35 |
Correct |
36 ms |
8780 KB |
Output is correct |
36 |
Correct |
94 ms |
18740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
18 ms |
7784 KB |
Output is correct |
4 |
Correct |
13 ms |
6672 KB |
Output is correct |
5 |
Correct |
34 ms |
11268 KB |
Output is correct |
6 |
Correct |
30 ms |
11264 KB |
Output is correct |
7 |
Correct |
33 ms |
11272 KB |
Output is correct |
8 |
Correct |
34 ms |
11256 KB |
Output is correct |
9 |
Correct |
31 ms |
11280 KB |
Output is correct |
10 |
Correct |
32 ms |
8836 KB |
Output is correct |
11 |
Correct |
66 ms |
15120 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
3 ms |
4164 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
35 ms |
10124 KB |
Output is correct |
23 |
Correct |
65 ms |
15200 KB |
Output is correct |
24 |
Correct |
67 ms |
15132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
7892 KB |
Output is correct |
2 |
Correct |
33 ms |
8948 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
99 ms |
18556 KB |
Output is correct |
6 |
Correct |
104 ms |
20260 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
55 ms |
11748 KB |
Output is correct |
9 |
Correct |
66 ms |
13768 KB |
Output is correct |
10 |
Correct |
27 ms |
8008 KB |
Output is correct |
11 |
Correct |
36 ms |
8996 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
27 ms |
7964 KB |
Output is correct |
19 |
Correct |
33 ms |
9032 KB |
Output is correct |
20 |
Correct |
27 ms |
7984 KB |
Output is correct |
21 |
Correct |
31 ms |
8716 KB |
Output is correct |
22 |
Correct |
28 ms |
8100 KB |
Output is correct |
23 |
Correct |
30 ms |
8576 KB |
Output is correct |
24 |
Correct |
2 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
4180 KB |
Output is correct |
26 |
Correct |
18 ms |
7784 KB |
Output is correct |
27 |
Correct |
13 ms |
6672 KB |
Output is correct |
28 |
Correct |
34 ms |
11268 KB |
Output is correct |
29 |
Correct |
30 ms |
11264 KB |
Output is correct |
30 |
Correct |
33 ms |
11272 KB |
Output is correct |
31 |
Correct |
34 ms |
11256 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
1 ms |
2644 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
1 ms |
2644 KB |
Output is correct |
40 |
Correct |
1 ms |
2644 KB |
Output is correct |
41 |
Correct |
2 ms |
2772 KB |
Output is correct |
42 |
Correct |
1 ms |
2644 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2772 KB |
Output is correct |
48 |
Correct |
14 ms |
4868 KB |
Output is correct |
49 |
Correct |
14 ms |
5120 KB |
Output is correct |
50 |
Correct |
14 ms |
5128 KB |
Output is correct |
51 |
Correct |
14 ms |
5096 KB |
Output is correct |
52 |
Correct |
15 ms |
5116 KB |
Output is correct |
53 |
Correct |
26 ms |
7596 KB |
Output is correct |
54 |
Correct |
4 ms |
3028 KB |
Output is correct |
55 |
Correct |
10 ms |
4164 KB |
Output is correct |
56 |
Correct |
1 ms |
2644 KB |
Output is correct |
57 |
Correct |
4 ms |
3028 KB |
Output is correct |
58 |
Correct |
2 ms |
2900 KB |
Output is correct |
59 |
Correct |
68 ms |
14324 KB |
Output is correct |
60 |
Correct |
97 ms |
18168 KB |
Output is correct |
61 |
Correct |
95 ms |
17820 KB |
Output is correct |
62 |
Correct |
96 ms |
17824 KB |
Output is correct |
63 |
Correct |
89 ms |
19244 KB |
Output is correct |
64 |
Correct |
98 ms |
17836 KB |
Output is correct |
65 |
Correct |
96 ms |
17824 KB |
Output is correct |
66 |
Correct |
36 ms |
8780 KB |
Output is correct |
67 |
Correct |
94 ms |
18740 KB |
Output is correct |
68 |
Correct |
31 ms |
11280 KB |
Output is correct |
69 |
Correct |
32 ms |
8836 KB |
Output is correct |
70 |
Correct |
66 ms |
15120 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
1 ms |
2644 KB |
Output is correct |
73 |
Correct |
1 ms |
2644 KB |
Output is correct |
74 |
Correct |
1 ms |
2644 KB |
Output is correct |
75 |
Correct |
1 ms |
2644 KB |
Output is correct |
76 |
Correct |
1 ms |
2644 KB |
Output is correct |
77 |
Correct |
3 ms |
4164 KB |
Output is correct |
78 |
Correct |
2 ms |
4180 KB |
Output is correct |
79 |
Correct |
2 ms |
4180 KB |
Output is correct |
80 |
Correct |
2 ms |
4180 KB |
Output is correct |
81 |
Correct |
35 ms |
10124 KB |
Output is correct |
82 |
Correct |
65 ms |
15200 KB |
Output is correct |
83 |
Correct |
67 ms |
15132 KB |
Output is correct |
84 |
Correct |
108 ms |
18824 KB |
Output is correct |
85 |
Correct |
105 ms |
18892 KB |
Output is correct |
86 |
Correct |
108 ms |
20484 KB |
Output is correct |
87 |
Correct |
110 ms |
20772 KB |
Output is correct |
88 |
Correct |
1 ms |
2644 KB |
Output is correct |
89 |
Correct |
110 ms |
20904 KB |
Output is correct |
90 |
Correct |
106 ms |
20428 KB |
Output is correct |
91 |
Correct |
97 ms |
20092 KB |
Output is correct |