# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
737700 |
2023-05-07T14:58:06 Z |
iee |
Catfish Farm (IOI22_fish) |
C++17 |
|
601 ms |
109148 KB |
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
map<int, ll> v[N], h[N];
vector<ll> f[N];
vector<int> pos[N];
vector<pair<int, ll>> S[N];
ll s(int p, int u) {
if (auto it = lower_bound(S[p].begin(), S[p].end(), pair(u + 1, (ll) -1e18)); it != S[p].begin()) return prev(it)->second;
return 0;
}
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
for (int i = 0; i < m; ++i)
v[x[i] + 1][y[i] + 1] += w[i], pos[x[i] + 1].push_back(y[i]);
for (int i = 1; i <= n; ++i) {
sort(pos[i].begin(), pos[i].end()), pos[i].push_back(n);
ll c = 0;
for (auto [p, v]: v[i])
c += v, S[i].emplace_back(p, c);
}
for (int j: pos[1])
h[1][j] = 0;
f[1].resize(pos[1].size());
for (int i = 2; i <= n; ++i) {
f[i].resize(pos[i].size());
auto g = pos[i - 1].size() - 1;
ll ma = -1e18;
for (int j = (int) pos[i].size() - 1; j >= 0; --j) {
while (~g && pos[i - 1][g] >= pos[i][j])
ma = max(ma, f[i - 1][g] + s(i, pos[i - 1][g])), --g;
f[i][j] = ma - s(i, pos[i][j]);
}
auto l = h[i - 1].begin();
ma = -1e18;
for (int j = 0; j < pos[i].size(); ++j) {
while (l != h[i - 1].end() && l->first <= pos[i][j])
ma = max(ma, l->second - s(i - 1, l->first)), ++l;
f[i][j] = max(f[i][j], h[i][pos[i][j]] = ma + s(i - 1, pos[i][j]));
}
for (int j = 0; j < pos[i - 1].size(); ++j)
h[i][pos[i - 1][j]] = max(h[i][pos[i - 1][j]], f[i - 1][j] + s(i, pos[i - 1][j]));
}
ll mx = 0;
for (ll v: f[n])
mx = max(mx, v);
return mx;
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 0; j < pos[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = 0; j < pos[i - 1].size(); ++j)
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
48720 KB |
Output is correct |
2 |
Correct |
182 ms |
54860 KB |
Output is correct |
3 |
Correct |
30 ms |
29148 KB |
Output is correct |
4 |
Correct |
29 ms |
29216 KB |
Output is correct |
5 |
Correct |
599 ms |
107280 KB |
Output is correct |
6 |
Correct |
434 ms |
109148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
16724 KB |
Output is correct |
2 |
Correct |
307 ms |
64808 KB |
Output is correct |
3 |
Correct |
379 ms |
74176 KB |
Output is correct |
4 |
Correct |
142 ms |
48628 KB |
Output is correct |
5 |
Correct |
187 ms |
54848 KB |
Output is correct |
6 |
Correct |
9 ms |
16724 KB |
Output is correct |
7 |
Correct |
9 ms |
16624 KB |
Output is correct |
8 |
Correct |
11 ms |
16736 KB |
Output is correct |
9 |
Correct |
9 ms |
16692 KB |
Output is correct |
10 |
Correct |
31 ms |
29132 KB |
Output is correct |
11 |
Correct |
30 ms |
29220 KB |
Output is correct |
12 |
Correct |
172 ms |
48776 KB |
Output is correct |
13 |
Correct |
173 ms |
54988 KB |
Output is correct |
14 |
Correct |
151 ms |
48736 KB |
Output is correct |
15 |
Correct |
166 ms |
49904 KB |
Output is correct |
16 |
Correct |
152 ms |
48700 KB |
Output is correct |
17 |
Correct |
173 ms |
52304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
29260 KB |
Output is correct |
2 |
Correct |
32 ms |
29212 KB |
Output is correct |
3 |
Correct |
76 ms |
38876 KB |
Output is correct |
4 |
Correct |
61 ms |
36668 KB |
Output is correct |
5 |
Correct |
133 ms |
48844 KB |
Output is correct |
6 |
Correct |
127 ms |
48228 KB |
Output is correct |
7 |
Correct |
120 ms |
48736 KB |
Output is correct |
8 |
Correct |
124 ms |
48824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
16740 KB |
Output is correct |
2 |
Correct |
10 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
4 |
Correct |
9 ms |
16740 KB |
Output is correct |
5 |
Correct |
9 ms |
16744 KB |
Output is correct |
6 |
Correct |
9 ms |
16724 KB |
Output is correct |
7 |
Correct |
9 ms |
16684 KB |
Output is correct |
8 |
Correct |
10 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16852 KB |
Output is correct |
10 |
Correct |
11 ms |
17236 KB |
Output is correct |
11 |
Correct |
11 ms |
16924 KB |
Output is correct |
12 |
Correct |
10 ms |
16980 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
10 ms |
16880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
16740 KB |
Output is correct |
2 |
Correct |
10 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
4 |
Correct |
9 ms |
16740 KB |
Output is correct |
5 |
Correct |
9 ms |
16744 KB |
Output is correct |
6 |
Correct |
9 ms |
16724 KB |
Output is correct |
7 |
Correct |
9 ms |
16684 KB |
Output is correct |
8 |
Correct |
10 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16852 KB |
Output is correct |
10 |
Correct |
11 ms |
17236 KB |
Output is correct |
11 |
Correct |
11 ms |
16924 KB |
Output is correct |
12 |
Correct |
10 ms |
16980 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
10 ms |
16880 KB |
Output is correct |
15 |
Correct |
9 ms |
16736 KB |
Output is correct |
16 |
Correct |
11 ms |
17236 KB |
Output is correct |
17 |
Correct |
58 ms |
26248 KB |
Output is correct |
18 |
Correct |
59 ms |
26536 KB |
Output is correct |
19 |
Correct |
56 ms |
26376 KB |
Output is correct |
20 |
Correct |
52 ms |
26016 KB |
Output is correct |
21 |
Correct |
49 ms |
26028 KB |
Output is correct |
22 |
Correct |
111 ms |
35308 KB |
Output is correct |
23 |
Correct |
19 ms |
19028 KB |
Output is correct |
24 |
Correct |
43 ms |
23868 KB |
Output is correct |
25 |
Correct |
11 ms |
16980 KB |
Output is correct |
26 |
Correct |
21 ms |
18800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
16740 KB |
Output is correct |
2 |
Correct |
10 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
4 |
Correct |
9 ms |
16740 KB |
Output is correct |
5 |
Correct |
9 ms |
16744 KB |
Output is correct |
6 |
Correct |
9 ms |
16724 KB |
Output is correct |
7 |
Correct |
9 ms |
16684 KB |
Output is correct |
8 |
Correct |
10 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16852 KB |
Output is correct |
10 |
Correct |
11 ms |
17236 KB |
Output is correct |
11 |
Correct |
11 ms |
16924 KB |
Output is correct |
12 |
Correct |
10 ms |
16980 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
10 ms |
16880 KB |
Output is correct |
15 |
Correct |
9 ms |
16736 KB |
Output is correct |
16 |
Correct |
11 ms |
17236 KB |
Output is correct |
17 |
Correct |
58 ms |
26248 KB |
Output is correct |
18 |
Correct |
59 ms |
26536 KB |
Output is correct |
19 |
Correct |
56 ms |
26376 KB |
Output is correct |
20 |
Correct |
52 ms |
26016 KB |
Output is correct |
21 |
Correct |
49 ms |
26028 KB |
Output is correct |
22 |
Correct |
111 ms |
35308 KB |
Output is correct |
23 |
Correct |
19 ms |
19028 KB |
Output is correct |
24 |
Correct |
43 ms |
23868 KB |
Output is correct |
25 |
Correct |
11 ms |
16980 KB |
Output is correct |
26 |
Correct |
21 ms |
18800 KB |
Output is correct |
27 |
Correct |
14 ms |
17776 KB |
Output is correct |
28 |
Correct |
328 ms |
63200 KB |
Output is correct |
29 |
Correct |
498 ms |
83284 KB |
Output is correct |
30 |
Correct |
501 ms |
95048 KB |
Output is correct |
31 |
Correct |
496 ms |
94928 KB |
Output is correct |
32 |
Correct |
426 ms |
77876 KB |
Output is correct |
33 |
Correct |
478 ms |
95640 KB |
Output is correct |
34 |
Correct |
479 ms |
95560 KB |
Output is correct |
35 |
Correct |
149 ms |
45872 KB |
Output is correct |
36 |
Correct |
461 ms |
93948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
29260 KB |
Output is correct |
2 |
Correct |
32 ms |
29212 KB |
Output is correct |
3 |
Correct |
76 ms |
38876 KB |
Output is correct |
4 |
Correct |
61 ms |
36668 KB |
Output is correct |
5 |
Correct |
133 ms |
48844 KB |
Output is correct |
6 |
Correct |
127 ms |
48228 KB |
Output is correct |
7 |
Correct |
120 ms |
48736 KB |
Output is correct |
8 |
Correct |
124 ms |
48824 KB |
Output is correct |
9 |
Correct |
173 ms |
54864 KB |
Output is correct |
10 |
Correct |
117 ms |
41840 KB |
Output is correct |
11 |
Correct |
232 ms |
67160 KB |
Output is correct |
12 |
Correct |
9 ms |
16744 KB |
Output is correct |
13 |
Correct |
10 ms |
16740 KB |
Output is correct |
14 |
Correct |
9 ms |
16724 KB |
Output is correct |
15 |
Correct |
11 ms |
16724 KB |
Output is correct |
16 |
Correct |
9 ms |
16724 KB |
Output is correct |
17 |
Correct |
9 ms |
16724 KB |
Output is correct |
18 |
Correct |
29 ms |
29152 KB |
Output is correct |
19 |
Correct |
29 ms |
29148 KB |
Output is correct |
20 |
Correct |
29 ms |
29224 KB |
Output is correct |
21 |
Correct |
30 ms |
29240 KB |
Output is correct |
22 |
Correct |
147 ms |
54976 KB |
Output is correct |
23 |
Correct |
246 ms |
73352 KB |
Output is correct |
24 |
Correct |
255 ms |
73876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
48720 KB |
Output is correct |
2 |
Correct |
182 ms |
54860 KB |
Output is correct |
3 |
Correct |
30 ms |
29148 KB |
Output is correct |
4 |
Correct |
29 ms |
29216 KB |
Output is correct |
5 |
Correct |
599 ms |
107280 KB |
Output is correct |
6 |
Correct |
434 ms |
109148 KB |
Output is correct |
7 |
Correct |
9 ms |
16724 KB |
Output is correct |
8 |
Correct |
307 ms |
64808 KB |
Output is correct |
9 |
Correct |
379 ms |
74176 KB |
Output is correct |
10 |
Correct |
142 ms |
48628 KB |
Output is correct |
11 |
Correct |
187 ms |
54848 KB |
Output is correct |
12 |
Correct |
9 ms |
16724 KB |
Output is correct |
13 |
Correct |
9 ms |
16624 KB |
Output is correct |
14 |
Correct |
11 ms |
16736 KB |
Output is correct |
15 |
Correct |
9 ms |
16692 KB |
Output is correct |
16 |
Correct |
31 ms |
29132 KB |
Output is correct |
17 |
Correct |
30 ms |
29220 KB |
Output is correct |
18 |
Correct |
172 ms |
48776 KB |
Output is correct |
19 |
Correct |
173 ms |
54988 KB |
Output is correct |
20 |
Correct |
151 ms |
48736 KB |
Output is correct |
21 |
Correct |
166 ms |
49904 KB |
Output is correct |
22 |
Correct |
152 ms |
48700 KB |
Output is correct |
23 |
Correct |
173 ms |
52304 KB |
Output is correct |
24 |
Correct |
31 ms |
29260 KB |
Output is correct |
25 |
Correct |
32 ms |
29212 KB |
Output is correct |
26 |
Correct |
76 ms |
38876 KB |
Output is correct |
27 |
Correct |
61 ms |
36668 KB |
Output is correct |
28 |
Correct |
133 ms |
48844 KB |
Output is correct |
29 |
Correct |
127 ms |
48228 KB |
Output is correct |
30 |
Correct |
120 ms |
48736 KB |
Output is correct |
31 |
Correct |
124 ms |
48824 KB |
Output is correct |
32 |
Correct |
9 ms |
16740 KB |
Output is correct |
33 |
Correct |
10 ms |
16724 KB |
Output is correct |
34 |
Correct |
10 ms |
16724 KB |
Output is correct |
35 |
Correct |
9 ms |
16740 KB |
Output is correct |
36 |
Correct |
9 ms |
16744 KB |
Output is correct |
37 |
Correct |
9 ms |
16724 KB |
Output is correct |
38 |
Correct |
9 ms |
16684 KB |
Output is correct |
39 |
Correct |
10 ms |
16724 KB |
Output is correct |
40 |
Correct |
9 ms |
16852 KB |
Output is correct |
41 |
Correct |
11 ms |
17236 KB |
Output is correct |
42 |
Correct |
11 ms |
16924 KB |
Output is correct |
43 |
Correct |
10 ms |
16980 KB |
Output is correct |
44 |
Correct |
9 ms |
16724 KB |
Output is correct |
45 |
Correct |
10 ms |
16880 KB |
Output is correct |
46 |
Correct |
9 ms |
16736 KB |
Output is correct |
47 |
Correct |
11 ms |
17236 KB |
Output is correct |
48 |
Correct |
58 ms |
26248 KB |
Output is correct |
49 |
Correct |
59 ms |
26536 KB |
Output is correct |
50 |
Correct |
56 ms |
26376 KB |
Output is correct |
51 |
Correct |
52 ms |
26016 KB |
Output is correct |
52 |
Correct |
49 ms |
26028 KB |
Output is correct |
53 |
Correct |
111 ms |
35308 KB |
Output is correct |
54 |
Correct |
19 ms |
19028 KB |
Output is correct |
55 |
Correct |
43 ms |
23868 KB |
Output is correct |
56 |
Correct |
11 ms |
16980 KB |
Output is correct |
57 |
Correct |
21 ms |
18800 KB |
Output is correct |
58 |
Correct |
14 ms |
17776 KB |
Output is correct |
59 |
Correct |
328 ms |
63200 KB |
Output is correct |
60 |
Correct |
498 ms |
83284 KB |
Output is correct |
61 |
Correct |
501 ms |
95048 KB |
Output is correct |
62 |
Correct |
496 ms |
94928 KB |
Output is correct |
63 |
Correct |
426 ms |
77876 KB |
Output is correct |
64 |
Correct |
478 ms |
95640 KB |
Output is correct |
65 |
Correct |
479 ms |
95560 KB |
Output is correct |
66 |
Correct |
149 ms |
45872 KB |
Output is correct |
67 |
Correct |
461 ms |
93948 KB |
Output is correct |
68 |
Correct |
173 ms |
54864 KB |
Output is correct |
69 |
Correct |
117 ms |
41840 KB |
Output is correct |
70 |
Correct |
232 ms |
67160 KB |
Output is correct |
71 |
Correct |
9 ms |
16744 KB |
Output is correct |
72 |
Correct |
10 ms |
16740 KB |
Output is correct |
73 |
Correct |
9 ms |
16724 KB |
Output is correct |
74 |
Correct |
11 ms |
16724 KB |
Output is correct |
75 |
Correct |
9 ms |
16724 KB |
Output is correct |
76 |
Correct |
9 ms |
16724 KB |
Output is correct |
77 |
Correct |
29 ms |
29152 KB |
Output is correct |
78 |
Correct |
29 ms |
29148 KB |
Output is correct |
79 |
Correct |
29 ms |
29224 KB |
Output is correct |
80 |
Correct |
30 ms |
29240 KB |
Output is correct |
81 |
Correct |
147 ms |
54976 KB |
Output is correct |
82 |
Correct |
246 ms |
73352 KB |
Output is correct |
83 |
Correct |
255 ms |
73876 KB |
Output is correct |
84 |
Correct |
601 ms |
102968 KB |
Output is correct |
85 |
Correct |
574 ms |
103500 KB |
Output is correct |
86 |
Correct |
427 ms |
106148 KB |
Output is correct |
87 |
Correct |
421 ms |
107976 KB |
Output is correct |
88 |
Correct |
12 ms |
16660 KB |
Output is correct |
89 |
Correct |
446 ms |
108092 KB |
Output is correct |
90 |
Correct |
473 ms |
102348 KB |
Output is correct |
91 |
Correct |
424 ms |
93720 KB |
Output is correct |