# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
630194 |
2022-08-15T23:36:03 Z |
ffao |
Catfish Farm (IOI22_fish) |
C++17 |
|
523 ms |
81824 KB |
#include "fish.h"
using namespace std;
#include <vector>
#include <algorithm>
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
vector< vector<int> > Ys_per_col(N);
vector<long long> colsum(N);
for (int i = 0; i < M; i++) colsum[X[i]] += W[i];
auto find = [&](int x, int y){ return (upper_bound(Ys_per_col[x].begin(), Ys_per_col[x].end(), y) - Ys_per_col[x].begin()) - 1; };
for (int i = 0; i < M; i++) { X.push_back(X[i]); Y.push_back(Y[i]+1); W.push_back(0); }
for (int i = 0; i < N; i++) { X.push_back(i); Y.push_back(-1); W.push_back(0); }
for (int i = 0; i < N; i++) { X.push_back(i); Y.push_back(N); W.push_back(0); }
for (int i = 0; i < X.size(); i++) {
Ys_per_col[X[i]].push_back(Y[i]);
if (X[i] > 0) Ys_per_col[X[i]-1].push_back(Y[i]);
if (X[i]+1 < N) Ys_per_col[X[i]+1].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(Ys_per_col[i].begin(), Ys_per_col[i].end());
Ys_per_col[i].erase( unique(Ys_per_col[i].begin(), Ys_per_col[i].end()), Ys_per_col[i].end());
}
vector< vector<int> > WW(N);
for (int i = 0; i < N; i++) WW[i].resize(Ys_per_col[i].size());
for (int i = 0; i < M; i++) {
int idx = find(X[i], Y[i]);
WW[X[i]][idx] = max(WW[X[i]][idx], W[i]);
}
vector< vector<long long> > dp[2];
for (int i = 0; i < 2; i++) {
dp[i].resize(N);
for (int j = 0; j < N; j++) dp[i][j].resize(Ys_per_col[j].size());
}
long long ans = 0;
for (int i = 1; i < N; i++) {
if (i >= 2) dp[0][i][0] = dp[1][i-2][0];
if (i >= 2) dp[0][i][ Ys_per_col[i].size() - 1 ] = dp[0][i-2][ Ys_per_col[i-2].size() - 1 ] + colsum[i-1];
for (int j = 1; j < (int)Ys_per_col[i].size(); j++) {
//cout << "setting " << i << " " << j << " val=" << Ys_per_col[i][j] << " idx=" << find(i-1, Ys_per_col[i][j]) << endl;
dp[0][i][j] = max(dp[0][i][j], dp[0][i][j-1] + WW[i-1][ find(i-1, Ys_per_col[i][j-1]) ]);
dp[0][i][j] = max(dp[0][i][j], dp[0][i-1][ find(i-1, Ys_per_col[i][j]) ]);
}
dp[1][i][ Ys_per_col[i].size() - 1 ] = dp[0][i-1][ Ys_per_col[i-1].size() - 1 ];
for (int j = (int)Ys_per_col[i].size() - 2; j >= 0; j--) {
dp[1][i][j] = dp[1][i][j+1] + WW[i][j];
dp[1][i][j] = max( dp[1][i][j], dp[1][i-1][ find(i-1, Ys_per_col[i][j] - 1) + 1 ]);
}
for (int j = 0; j < (int)Ys_per_col[i].size(); j++) {
ans = max(ans, dp[0][i][j]);
ans = max(ans, dp[1][i][j]);
}
}
/*for (int k = 0; k < 2; k++) {
for (int i = 1; i < N; i++) {
for (int j = 0; j < (int)Ys_per_col[i].size(); j++) {
cout << "dp[" << k << "][" << i << "][" << j << "] = " << dp[k][i][j] << " (" << i << ", " << Ys_per_col[i][j] << ")" << endl;
}
}
}*/
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
32064 KB |
Output is correct |
2 |
Correct |
144 ms |
36040 KB |
Output is correct |
3 |
Correct |
49 ms |
26804 KB |
Output is correct |
4 |
Correct |
48 ms |
26840 KB |
Output is correct |
5 |
Correct |
439 ms |
65420 KB |
Output is correct |
6 |
Correct |
404 ms |
81824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
213 ms |
38644 KB |
Output is correct |
3 |
Correct |
240 ms |
44240 KB |
Output is correct |
4 |
Correct |
120 ms |
32136 KB |
Output is correct |
5 |
Correct |
135 ms |
36220 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
47 ms |
26812 KB |
Output is correct |
11 |
Correct |
49 ms |
26856 KB |
Output is correct |
12 |
Correct |
141 ms |
34920 KB |
Output is correct |
13 |
Correct |
176 ms |
39232 KB |
Output is correct |
14 |
Correct |
133 ms |
33492 KB |
Output is correct |
15 |
Correct |
141 ms |
35216 KB |
Output is correct |
16 |
Correct |
131 ms |
33520 KB |
Output is correct |
17 |
Correct |
156 ms |
37172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
26804 KB |
Output is correct |
2 |
Correct |
48 ms |
26884 KB |
Output is correct |
3 |
Correct |
86 ms |
30188 KB |
Output is correct |
4 |
Correct |
87 ms |
31076 KB |
Output is correct |
5 |
Correct |
136 ms |
37136 KB |
Output is correct |
6 |
Correct |
128 ms |
37316 KB |
Output is correct |
7 |
Correct |
131 ms |
37400 KB |
Output is correct |
8 |
Correct |
135 ms |
37344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
37 ms |
4736 KB |
Output is correct |
18 |
Correct |
38 ms |
4416 KB |
Output is correct |
19 |
Correct |
34 ms |
4280 KB |
Output is correct |
20 |
Correct |
33 ms |
4200 KB |
Output is correct |
21 |
Correct |
31 ms |
4188 KB |
Output is correct |
22 |
Correct |
65 ms |
7812 KB |
Output is correct |
23 |
Correct |
13 ms |
1736 KB |
Output is correct |
24 |
Correct |
30 ms |
4504 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
1556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
37 ms |
4736 KB |
Output is correct |
18 |
Correct |
38 ms |
4416 KB |
Output is correct |
19 |
Correct |
34 ms |
4280 KB |
Output is correct |
20 |
Correct |
33 ms |
4200 KB |
Output is correct |
21 |
Correct |
31 ms |
4188 KB |
Output is correct |
22 |
Correct |
65 ms |
7812 KB |
Output is correct |
23 |
Correct |
13 ms |
1736 KB |
Output is correct |
24 |
Correct |
30 ms |
4504 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
1556 KB |
Output is correct |
27 |
Correct |
3 ms |
1492 KB |
Output is correct |
28 |
Correct |
174 ms |
19500 KB |
Output is correct |
29 |
Correct |
309 ms |
30488 KB |
Output is correct |
30 |
Correct |
355 ms |
54348 KB |
Output is correct |
31 |
Correct |
362 ms |
53780 KB |
Output is correct |
32 |
Correct |
230 ms |
25888 KB |
Output is correct |
33 |
Correct |
379 ms |
56336 KB |
Output is correct |
34 |
Correct |
387 ms |
56468 KB |
Output is correct |
35 |
Correct |
94 ms |
15868 KB |
Output is correct |
36 |
Correct |
318 ms |
42624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
26804 KB |
Output is correct |
2 |
Correct |
48 ms |
26884 KB |
Output is correct |
3 |
Correct |
86 ms |
30188 KB |
Output is correct |
4 |
Correct |
87 ms |
31076 KB |
Output is correct |
5 |
Correct |
136 ms |
37136 KB |
Output is correct |
6 |
Correct |
128 ms |
37316 KB |
Output is correct |
7 |
Correct |
131 ms |
37400 KB |
Output is correct |
8 |
Correct |
135 ms |
37344 KB |
Output is correct |
9 |
Correct |
163 ms |
40492 KB |
Output is correct |
10 |
Correct |
104 ms |
23676 KB |
Output is correct |
11 |
Correct |
216 ms |
46924 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
47 ms |
26804 KB |
Output is correct |
19 |
Correct |
47 ms |
26868 KB |
Output is correct |
20 |
Correct |
48 ms |
26804 KB |
Output is correct |
21 |
Correct |
47 ms |
26892 KB |
Output is correct |
22 |
Correct |
223 ms |
44248 KB |
Output is correct |
23 |
Correct |
259 ms |
51724 KB |
Output is correct |
24 |
Correct |
247 ms |
51980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
32064 KB |
Output is correct |
2 |
Correct |
144 ms |
36040 KB |
Output is correct |
3 |
Correct |
49 ms |
26804 KB |
Output is correct |
4 |
Correct |
48 ms |
26840 KB |
Output is correct |
5 |
Correct |
439 ms |
65420 KB |
Output is correct |
6 |
Correct |
404 ms |
81824 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
213 ms |
38644 KB |
Output is correct |
9 |
Correct |
240 ms |
44240 KB |
Output is correct |
10 |
Correct |
120 ms |
32136 KB |
Output is correct |
11 |
Correct |
135 ms |
36220 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
47 ms |
26812 KB |
Output is correct |
17 |
Correct |
49 ms |
26856 KB |
Output is correct |
18 |
Correct |
141 ms |
34920 KB |
Output is correct |
19 |
Correct |
176 ms |
39232 KB |
Output is correct |
20 |
Correct |
133 ms |
33492 KB |
Output is correct |
21 |
Correct |
141 ms |
35216 KB |
Output is correct |
22 |
Correct |
131 ms |
33520 KB |
Output is correct |
23 |
Correct |
156 ms |
37172 KB |
Output is correct |
24 |
Correct |
48 ms |
26804 KB |
Output is correct |
25 |
Correct |
48 ms |
26884 KB |
Output is correct |
26 |
Correct |
86 ms |
30188 KB |
Output is correct |
27 |
Correct |
87 ms |
31076 KB |
Output is correct |
28 |
Correct |
136 ms |
37136 KB |
Output is correct |
29 |
Correct |
128 ms |
37316 KB |
Output is correct |
30 |
Correct |
131 ms |
37400 KB |
Output is correct |
31 |
Correct |
135 ms |
37344 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
37 ms |
4736 KB |
Output is correct |
49 |
Correct |
38 ms |
4416 KB |
Output is correct |
50 |
Correct |
34 ms |
4280 KB |
Output is correct |
51 |
Correct |
33 ms |
4200 KB |
Output is correct |
52 |
Correct |
31 ms |
4188 KB |
Output is correct |
53 |
Correct |
65 ms |
7812 KB |
Output is correct |
54 |
Correct |
13 ms |
1736 KB |
Output is correct |
55 |
Correct |
30 ms |
4504 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
10 ms |
1556 KB |
Output is correct |
58 |
Correct |
3 ms |
1492 KB |
Output is correct |
59 |
Correct |
174 ms |
19500 KB |
Output is correct |
60 |
Correct |
309 ms |
30488 KB |
Output is correct |
61 |
Correct |
355 ms |
54348 KB |
Output is correct |
62 |
Correct |
362 ms |
53780 KB |
Output is correct |
63 |
Correct |
230 ms |
25888 KB |
Output is correct |
64 |
Correct |
379 ms |
56336 KB |
Output is correct |
65 |
Correct |
387 ms |
56468 KB |
Output is correct |
66 |
Correct |
94 ms |
15868 KB |
Output is correct |
67 |
Correct |
318 ms |
42624 KB |
Output is correct |
68 |
Correct |
163 ms |
40492 KB |
Output is correct |
69 |
Correct |
104 ms |
23676 KB |
Output is correct |
70 |
Correct |
216 ms |
46924 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
0 ms |
212 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
47 ms |
26804 KB |
Output is correct |
78 |
Correct |
47 ms |
26868 KB |
Output is correct |
79 |
Correct |
48 ms |
26804 KB |
Output is correct |
80 |
Correct |
47 ms |
26892 KB |
Output is correct |
81 |
Correct |
223 ms |
44248 KB |
Output is correct |
82 |
Correct |
259 ms |
51724 KB |
Output is correct |
83 |
Correct |
247 ms |
51980 KB |
Output is correct |
84 |
Correct |
496 ms |
68256 KB |
Output is correct |
85 |
Correct |
523 ms |
69772 KB |
Output is correct |
86 |
Correct |
396 ms |
78368 KB |
Output is correct |
87 |
Correct |
400 ms |
81556 KB |
Output is correct |
88 |
Correct |
0 ms |
212 KB |
Output is correct |
89 |
Correct |
395 ms |
81500 KB |
Output is correct |
90 |
Correct |
343 ms |
64956 KB |
Output is correct |
91 |
Correct |
263 ms |
55164 KB |
Output is correct |