# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1033486 |
2024-07-24T22:24:11 Z |
Tonyl |
Catfish Farm (IOI22_fish) |
C++17 |
|
223 ms |
56660 KB |
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define REP(i,n) for (int i = 0; i < n; i++)
#define trav(a,x) for (auto &a : x)
#define all(x) (x).begin(), (x).end()
#define D(x) cerr << #x << ": " << x << endl;
struct Event {
int height;
int belowFish = 0;
ll pure = 0;
ll help = 0;
Event(int h, int b = 0) : height(h), belowFish(b) {}
bool operator<(Event &other) {
return height < other.height;
}
void debug() {
assert(help >= pure);
cerr << height << " (" << belowFish << "): " << help << "/" << pure << endl;
}
};
const int MAX_N = 100001;
vector<Event> dp[MAX_N];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
REP(i,M) {
int x = X[i];
int y = Y[i];
int w = W[i];
dp[x].push_back(Event(y-1, w));
if (x != 0) dp[x-1].push_back(Event(y));
if (x != N-1) dp[x+1].push_back(Event(y));
}
REP(x,N) {
dp[x].push_back(Event(-2));
dp[x].push_back(Event(N));
sort(all(dp[x]));
}
for (int x = 1; x < N; x++) {
ll top_default = 0;
trav(e, dp[x-1]) top_default = max(top_default, e.help);
// pure
int lf = 0; int maxlf = dp[x-1].size()-1;
ll sofar = 0;
REP(me, dp[x].size()) {
while (lf != maxlf && dp[x-1][lf+1].height < dp[x][me].height) {
lf++;
sofar = max(sofar, dp[x-1][lf].pure);
sofar += dp[x-1][lf].belowFish;
}
dp[x][me].pure = max(top_default, sofar);
}
// with help
lf = maxlf;
sofar = 0;
for (int me = dp[x].size()-1; me >= 0; me--) {
while (lf != 0 && dp[x-1][lf-1].height > dp[x][me].height) {
lf--;
sofar = max(sofar, dp[x-1][lf].help);
}
sofar += dp[x][me].belowFish;
dp[x][me].help = max(dp[x][me].pure, sofar);
}
}
/*for (int x = 0; x < N; x++) {
D(x);
trav(e, dp[x]) e.debug();
}*/
ll abs_top = 0;
trav(e, dp[N-1]) abs_top = max(abs_top, e.help);
return abs_top;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:7:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define REP(i,n) for (int i = 0; i < n; i++)
......
56 | REP(me, dp[x].size()) {
| ~~~~~~~~~~~~~~~~
fish.cpp:56:5: note: in expansion of macro 'REP'
56 | REP(me, dp[x].size()) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
15408 KB |
Output is correct |
2 |
Correct |
44 ms |
17708 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
9 ms |
8928 KB |
Output is correct |
5 |
Correct |
149 ms |
43524 KB |
Output is correct |
6 |
Correct |
180 ms |
56660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
75 ms |
24324 KB |
Output is correct |
3 |
Correct |
95 ms |
28920 KB |
Output is correct |
4 |
Correct |
38 ms |
15408 KB |
Output is correct |
5 |
Correct |
45 ms |
17616 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
9 ms |
9048 KB |
Output is correct |
11 |
Correct |
9 ms |
9052 KB |
Output is correct |
12 |
Correct |
52 ms |
17508 KB |
Output is correct |
13 |
Correct |
54 ms |
20064 KB |
Output is correct |
14 |
Correct |
51 ms |
16368 KB |
Output is correct |
15 |
Correct |
45 ms |
18020 KB |
Output is correct |
16 |
Correct |
41 ms |
16308 KB |
Output is correct |
17 |
Correct |
45 ms |
17764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9052 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
33 ms |
18268 KB |
Output is correct |
4 |
Correct |
27 ms |
15708 KB |
Output is correct |
5 |
Correct |
59 ms |
29012 KB |
Output is correct |
6 |
Correct |
54 ms |
28496 KB |
Output is correct |
7 |
Correct |
58 ms |
28876 KB |
Output is correct |
8 |
Correct |
59 ms |
29008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2908 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
2 ms |
2816 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2908 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
2 ms |
2816 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2804 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
2 ms |
2908 KB |
Output is correct |
17 |
Correct |
19 ms |
9388 KB |
Output is correct |
18 |
Correct |
19 ms |
8796 KB |
Output is correct |
19 |
Correct |
17 ms |
8428 KB |
Output is correct |
20 |
Correct |
17 ms |
8540 KB |
Output is correct |
21 |
Correct |
17 ms |
8532 KB |
Output is correct |
22 |
Correct |
36 ms |
14320 KB |
Output is correct |
23 |
Correct |
5 ms |
4184 KB |
Output is correct |
24 |
Correct |
13 ms |
7880 KB |
Output is correct |
25 |
Correct |
3 ms |
2908 KB |
Output is correct |
26 |
Correct |
5 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2908 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
2 ms |
2816 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2804 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
2 ms |
2908 KB |
Output is correct |
17 |
Correct |
19 ms |
9388 KB |
Output is correct |
18 |
Correct |
19 ms |
8796 KB |
Output is correct |
19 |
Correct |
17 ms |
8428 KB |
Output is correct |
20 |
Correct |
17 ms |
8540 KB |
Output is correct |
21 |
Correct |
17 ms |
8532 KB |
Output is correct |
22 |
Correct |
36 ms |
14320 KB |
Output is correct |
23 |
Correct |
5 ms |
4184 KB |
Output is correct |
24 |
Correct |
13 ms |
7880 KB |
Output is correct |
25 |
Correct |
3 ms |
2908 KB |
Output is correct |
26 |
Correct |
5 ms |
3932 KB |
Output is correct |
27 |
Correct |
3 ms |
3416 KB |
Output is correct |
28 |
Correct |
99 ms |
30404 KB |
Output is correct |
29 |
Correct |
156 ms |
42000 KB |
Output is correct |
30 |
Correct |
135 ms |
53332 KB |
Output is correct |
31 |
Correct |
137 ms |
53272 KB |
Output is correct |
32 |
Correct |
112 ms |
42068 KB |
Output is correct |
33 |
Correct |
154 ms |
53328 KB |
Output is correct |
34 |
Correct |
223 ms |
53328 KB |
Output is correct |
35 |
Correct |
50 ms |
20824 KB |
Output is correct |
36 |
Correct |
124 ms |
44564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9052 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
33 ms |
18268 KB |
Output is correct |
4 |
Correct |
27 ms |
15708 KB |
Output is correct |
5 |
Correct |
59 ms |
29012 KB |
Output is correct |
6 |
Correct |
54 ms |
28496 KB |
Output is correct |
7 |
Correct |
58 ms |
28876 KB |
Output is correct |
8 |
Correct |
59 ms |
29008 KB |
Output is correct |
9 |
Correct |
57 ms |
28752 KB |
Output is correct |
10 |
Correct |
56 ms |
18004 KB |
Output is correct |
11 |
Correct |
96 ms |
33108 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2792 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
9 ms |
8932 KB |
Output is correct |
19 |
Correct |
9 ms |
8812 KB |
Output is correct |
20 |
Correct |
9 ms |
9052 KB |
Output is correct |
21 |
Correct |
9 ms |
9052 KB |
Output is correct |
22 |
Correct |
63 ms |
25584 KB |
Output is correct |
23 |
Correct |
89 ms |
33108 KB |
Output is correct |
24 |
Correct |
98 ms |
33576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
15408 KB |
Output is correct |
2 |
Correct |
44 ms |
17708 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
9 ms |
8928 KB |
Output is correct |
5 |
Correct |
149 ms |
43524 KB |
Output is correct |
6 |
Correct |
180 ms |
56660 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
75 ms |
24324 KB |
Output is correct |
9 |
Correct |
95 ms |
28920 KB |
Output is correct |
10 |
Correct |
38 ms |
15408 KB |
Output is correct |
11 |
Correct |
45 ms |
17616 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
9 ms |
9048 KB |
Output is correct |
17 |
Correct |
9 ms |
9052 KB |
Output is correct |
18 |
Correct |
52 ms |
17508 KB |
Output is correct |
19 |
Correct |
54 ms |
20064 KB |
Output is correct |
20 |
Correct |
51 ms |
16368 KB |
Output is correct |
21 |
Correct |
45 ms |
18020 KB |
Output is correct |
22 |
Correct |
41 ms |
16308 KB |
Output is correct |
23 |
Correct |
45 ms |
17764 KB |
Output is correct |
24 |
Correct |
13 ms |
9052 KB |
Output is correct |
25 |
Correct |
9 ms |
9052 KB |
Output is correct |
26 |
Correct |
33 ms |
18268 KB |
Output is correct |
27 |
Correct |
27 ms |
15708 KB |
Output is correct |
28 |
Correct |
59 ms |
29012 KB |
Output is correct |
29 |
Correct |
54 ms |
28496 KB |
Output is correct |
30 |
Correct |
58 ms |
28876 KB |
Output is correct |
31 |
Correct |
59 ms |
29008 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2908 KB |
Output is correct |
42 |
Correct |
2 ms |
2908 KB |
Output is correct |
43 |
Correct |
2 ms |
2816 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2804 KB |
Output is correct |
46 |
Correct |
1 ms |
2652 KB |
Output is correct |
47 |
Correct |
2 ms |
2908 KB |
Output is correct |
48 |
Correct |
19 ms |
9388 KB |
Output is correct |
49 |
Correct |
19 ms |
8796 KB |
Output is correct |
50 |
Correct |
17 ms |
8428 KB |
Output is correct |
51 |
Correct |
17 ms |
8540 KB |
Output is correct |
52 |
Correct |
17 ms |
8532 KB |
Output is correct |
53 |
Correct |
36 ms |
14320 KB |
Output is correct |
54 |
Correct |
5 ms |
4184 KB |
Output is correct |
55 |
Correct |
13 ms |
7880 KB |
Output is correct |
56 |
Correct |
3 ms |
2908 KB |
Output is correct |
57 |
Correct |
5 ms |
3932 KB |
Output is correct |
58 |
Correct |
3 ms |
3416 KB |
Output is correct |
59 |
Correct |
99 ms |
30404 KB |
Output is correct |
60 |
Correct |
156 ms |
42000 KB |
Output is correct |
61 |
Correct |
135 ms |
53332 KB |
Output is correct |
62 |
Correct |
137 ms |
53272 KB |
Output is correct |
63 |
Correct |
112 ms |
42068 KB |
Output is correct |
64 |
Correct |
154 ms |
53328 KB |
Output is correct |
65 |
Correct |
223 ms |
53328 KB |
Output is correct |
66 |
Correct |
50 ms |
20824 KB |
Output is correct |
67 |
Correct |
124 ms |
44564 KB |
Output is correct |
68 |
Correct |
57 ms |
28752 KB |
Output is correct |
69 |
Correct |
56 ms |
18004 KB |
Output is correct |
70 |
Correct |
96 ms |
33108 KB |
Output is correct |
71 |
Correct |
1 ms |
2652 KB |
Output is correct |
72 |
Correct |
1 ms |
2652 KB |
Output is correct |
73 |
Correct |
2 ms |
2792 KB |
Output is correct |
74 |
Correct |
1 ms |
2652 KB |
Output is correct |
75 |
Correct |
1 ms |
2652 KB |
Output is correct |
76 |
Correct |
1 ms |
2652 KB |
Output is correct |
77 |
Correct |
9 ms |
8932 KB |
Output is correct |
78 |
Correct |
9 ms |
8812 KB |
Output is correct |
79 |
Correct |
9 ms |
9052 KB |
Output is correct |
80 |
Correct |
9 ms |
9052 KB |
Output is correct |
81 |
Correct |
63 ms |
25584 KB |
Output is correct |
82 |
Correct |
89 ms |
33108 KB |
Output is correct |
83 |
Correct |
98 ms |
33576 KB |
Output is correct |
84 |
Correct |
169 ms |
43424 KB |
Output is correct |
85 |
Correct |
150 ms |
43056 KB |
Output is correct |
86 |
Correct |
176 ms |
54400 KB |
Output is correct |
87 |
Correct |
165 ms |
56660 KB |
Output is correct |
88 |
Correct |
1 ms |
2652 KB |
Output is correct |
89 |
Correct |
156 ms |
56448 KB |
Output is correct |
90 |
Correct |
138 ms |
53080 KB |
Output is correct |
91 |
Correct |
130 ms |
51336 KB |
Output is correct |