# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
831209 |
2023-08-19T22:29:22 Z |
Wael |
Catfish Farm (IOI22_fish) |
C++17 |
|
548 ms |
124320 KB |
#include <bits/stdc++.h>
using namespace std;
#include "fish.h"
int const Mx = 1e5 + 10;
int n , m , j , Req , ReqNext;
map<int , int>cost[Mx] , vis[Mx];
vector<int>possible[Mx];
vector<long long>pref[Mx] , dp[2][Mx];
long long max_weights(int N, int M , vector<int> X, vector<int> Y, vector<int> W) {
m = M , n = N;
long long ans = 0;
for(int i = 0 ; i < m ; ++i) {
++X[i];
++Y[i];
possible[X[i] - 1].push_back(Y[i]);
possible[X[i] + 1].push_back(Y[i]);
possible[X[i]].push_back(Y[i]);
cost[X[i]][Y[i]] = W[i];
}
for(int i = 1 ; i <= n + 1 ; ++i) {
possible[i].push_back(0);
vector<int>Cur;
sort(possible[i].begin() , possible[i].end());
for(auto j : possible[i]) if(Cur.size() == 0 || Cur.back() != j) Cur.push_back(j);
possible[i] = Cur;
for(auto j : possible[i]) {
long long cur = 0;
if(pref[i].size()) cur = pref[i].back();
cur += cost[i][j];
pref[i].push_back(cur);
dp[0][i].push_back(0);
dp[1][i].push_back(0);
}
}
long long MaxPref = 0 , MaxSuf = pref[2].back() , MaxDp = 0 , MaxAddDp = 0;
for(int i = 2 ; i <= n ; ++i) {
Req = 0 , ReqNext = 0;
for(int J = 0 ; J < possible[i].size() ; ++J) {
j = possible[i][J];
while(Req + 1 < possible[i - 1].size() && possible[i - 1][Req + 1] <= j) ++Req;
dp[0][i][J] = max(dp[0][i][J] , MaxPref + pref[i - 1][Req]);
dp[1][i][J] = max(dp[1][i][J] , MaxSuf - pref[i][J]);
if(i >= 3) {
dp[0][i][J] = max(dp[0][i][J] , MaxDp + pref[i - 1][Req]);
dp[0][i][J] = max(dp[0][i][J] , MaxAddDp - pref[i - 1][Req]);
}
ans = max(ans , dp[0][i][J]);
ans = max(ans , dp[1][i][J]);
}
MaxPref = MaxSuf = MaxDp = MaxAddDp = 0;
for(int J = 0 ; J < possible[i].size() ; ++J) {
j = possible[i][J];
while(ReqNext + 1 < possible[i + 1].size() && possible[i + 1][ReqNext + 1] <= j) ++ReqNext;
MaxPref = max(MaxPref , dp[0][i][J] - pref[i][J]);
MaxSuf = max(MaxSuf , max(dp[0][i][J] , dp[1][i][J]) + pref[i + 1][ReqNext]);
}
Req = 0;
for(int J = 0 ; J < possible[i - 1].size() ; ++J) {
j = possible[i - 1][J];
while(Req + 1 < possible[i].size() && possible[i][Req + 1] <= j) ++Req;
MaxDp = max(MaxDp , max(dp[0][i - 1][J] , dp[1][i - 1][J]));
MaxAddDp = max(MaxAddDp , max(dp[0][i - 1][J] , dp[1][i - 1][J]) + pref[i][Req]);
}
}
return ans;
}
/*
pref = max Dp - prefi
suf = max Dp - prefi + 1
Pref = max Dp
Suf = max Dp + prefi + 1
*/
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:42:27: 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 < possible[i].size() ; ++J) {
| ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while(Req + 1 < possible[i - 1].size() && possible[i - 1][Req + 1] <= j) ++Req;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int J = 0 ; J < possible[i].size() ; ++J) {
| ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while(ReqNext + 1 < possible[i + 1].size() && possible[i + 1][ReqNext + 1] <= j) ++ReqNext;
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int J = 0 ; J < possible[i - 1].size() ; ++J) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | while(Req + 1 < possible[i].size() && possible[i][Req + 1] <= j) ++Req;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
49140 KB |
Output is correct |
2 |
Correct |
135 ms |
54128 KB |
Output is correct |
3 |
Correct |
40 ms |
36292 KB |
Output is correct |
4 |
Correct |
44 ms |
36172 KB |
Output is correct |
5 |
Correct |
436 ms |
112356 KB |
Output is correct |
6 |
Correct |
548 ms |
117548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19024 KB |
Output is correct |
2 |
Correct |
189 ms |
58912 KB |
Output is correct |
3 |
Correct |
229 ms |
64916 KB |
Output is correct |
4 |
Correct |
111 ms |
49208 KB |
Output is correct |
5 |
Correct |
133 ms |
54136 KB |
Output is correct |
6 |
Correct |
9 ms |
19028 KB |
Output is correct |
7 |
Correct |
10 ms |
19076 KB |
Output is correct |
8 |
Correct |
10 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19032 KB |
Output is correct |
10 |
Correct |
40 ms |
36232 KB |
Output is correct |
11 |
Correct |
41 ms |
36200 KB |
Output is correct |
12 |
Correct |
128 ms |
55400 KB |
Output is correct |
13 |
Correct |
160 ms |
61416 KB |
Output is correct |
14 |
Correct |
123 ms |
52356 KB |
Output is correct |
15 |
Correct |
138 ms |
49736 KB |
Output is correct |
16 |
Correct |
129 ms |
52332 KB |
Output is correct |
17 |
Correct |
136 ms |
55696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
36308 KB |
Output is correct |
2 |
Correct |
41 ms |
36244 KB |
Output is correct |
3 |
Correct |
84 ms |
38584 KB |
Output is correct |
4 |
Correct |
68 ms |
39232 KB |
Output is correct |
5 |
Correct |
146 ms |
43288 KB |
Output is correct |
6 |
Correct |
112 ms |
43340 KB |
Output is correct |
7 |
Correct |
119 ms |
43312 KB |
Output is correct |
8 |
Correct |
117 ms |
43296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19092 KB |
Output is correct |
5 |
Correct |
12 ms |
19088 KB |
Output is correct |
6 |
Correct |
9 ms |
19028 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
9 |
Correct |
10 ms |
19124 KB |
Output is correct |
10 |
Correct |
10 ms |
19448 KB |
Output is correct |
11 |
Correct |
10 ms |
19204 KB |
Output is correct |
12 |
Correct |
10 ms |
19284 KB |
Output is correct |
13 |
Correct |
9 ms |
19024 KB |
Output is correct |
14 |
Correct |
10 ms |
19156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19092 KB |
Output is correct |
5 |
Correct |
12 ms |
19088 KB |
Output is correct |
6 |
Correct |
9 ms |
19028 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
9 |
Correct |
10 ms |
19124 KB |
Output is correct |
10 |
Correct |
10 ms |
19448 KB |
Output is correct |
11 |
Correct |
10 ms |
19204 KB |
Output is correct |
12 |
Correct |
10 ms |
19284 KB |
Output is correct |
13 |
Correct |
9 ms |
19024 KB |
Output is correct |
14 |
Correct |
10 ms |
19156 KB |
Output is correct |
15 |
Correct |
9 ms |
19156 KB |
Output is correct |
16 |
Correct |
11 ms |
19384 KB |
Output is correct |
17 |
Correct |
42 ms |
26156 KB |
Output is correct |
18 |
Correct |
41 ms |
25252 KB |
Output is correct |
19 |
Correct |
39 ms |
25464 KB |
Output is correct |
20 |
Correct |
37 ms |
24784 KB |
Output is correct |
21 |
Correct |
39 ms |
24608 KB |
Output is correct |
22 |
Correct |
70 ms |
30284 KB |
Output is correct |
23 |
Correct |
17 ms |
21416 KB |
Output is correct |
24 |
Correct |
35 ms |
25180 KB |
Output is correct |
25 |
Correct |
11 ms |
19284 KB |
Output is correct |
26 |
Correct |
19 ms |
21268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19092 KB |
Output is correct |
5 |
Correct |
12 ms |
19088 KB |
Output is correct |
6 |
Correct |
9 ms |
19028 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
9 |
Correct |
10 ms |
19124 KB |
Output is correct |
10 |
Correct |
10 ms |
19448 KB |
Output is correct |
11 |
Correct |
10 ms |
19204 KB |
Output is correct |
12 |
Correct |
10 ms |
19284 KB |
Output is correct |
13 |
Correct |
9 ms |
19024 KB |
Output is correct |
14 |
Correct |
10 ms |
19156 KB |
Output is correct |
15 |
Correct |
9 ms |
19156 KB |
Output is correct |
16 |
Correct |
11 ms |
19384 KB |
Output is correct |
17 |
Correct |
42 ms |
26156 KB |
Output is correct |
18 |
Correct |
41 ms |
25252 KB |
Output is correct |
19 |
Correct |
39 ms |
25464 KB |
Output is correct |
20 |
Correct |
37 ms |
24784 KB |
Output is correct |
21 |
Correct |
39 ms |
24608 KB |
Output is correct |
22 |
Correct |
70 ms |
30284 KB |
Output is correct |
23 |
Correct |
17 ms |
21416 KB |
Output is correct |
24 |
Correct |
35 ms |
25180 KB |
Output is correct |
25 |
Correct |
11 ms |
19284 KB |
Output is correct |
26 |
Correct |
19 ms |
21268 KB |
Output is correct |
27 |
Correct |
13 ms |
20112 KB |
Output is correct |
28 |
Correct |
203 ms |
48624 KB |
Output is correct |
29 |
Correct |
295 ms |
68300 KB |
Output is correct |
30 |
Correct |
381 ms |
108232 KB |
Output is correct |
31 |
Correct |
368 ms |
107352 KB |
Output is correct |
32 |
Correct |
273 ms |
57800 KB |
Output is correct |
33 |
Correct |
374 ms |
109332 KB |
Output is correct |
34 |
Correct |
371 ms |
109276 KB |
Output is correct |
35 |
Correct |
114 ms |
45024 KB |
Output is correct |
36 |
Correct |
359 ms |
93276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
36308 KB |
Output is correct |
2 |
Correct |
41 ms |
36244 KB |
Output is correct |
3 |
Correct |
84 ms |
38584 KB |
Output is correct |
4 |
Correct |
68 ms |
39232 KB |
Output is correct |
5 |
Correct |
146 ms |
43288 KB |
Output is correct |
6 |
Correct |
112 ms |
43340 KB |
Output is correct |
7 |
Correct |
119 ms |
43312 KB |
Output is correct |
8 |
Correct |
117 ms |
43296 KB |
Output is correct |
9 |
Correct |
175 ms |
57432 KB |
Output is correct |
10 |
Correct |
106 ms |
38480 KB |
Output is correct |
11 |
Correct |
230 ms |
57944 KB |
Output is correct |
12 |
Correct |
9 ms |
19028 KB |
Output is correct |
13 |
Correct |
9 ms |
19080 KB |
Output is correct |
14 |
Correct |
9 ms |
19028 KB |
Output is correct |
15 |
Correct |
9 ms |
19092 KB |
Output is correct |
16 |
Correct |
9 ms |
19056 KB |
Output is correct |
17 |
Correct |
10 ms |
19092 KB |
Output is correct |
18 |
Correct |
41 ms |
36296 KB |
Output is correct |
19 |
Correct |
42 ms |
36308 KB |
Output is correct |
20 |
Correct |
41 ms |
36236 KB |
Output is correct |
21 |
Correct |
42 ms |
36216 KB |
Output is correct |
22 |
Correct |
207 ms |
60720 KB |
Output is correct |
23 |
Correct |
271 ms |
72524 KB |
Output is correct |
24 |
Correct |
273 ms |
74344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
49140 KB |
Output is correct |
2 |
Correct |
135 ms |
54128 KB |
Output is correct |
3 |
Correct |
40 ms |
36292 KB |
Output is correct |
4 |
Correct |
44 ms |
36172 KB |
Output is correct |
5 |
Correct |
436 ms |
112356 KB |
Output is correct |
6 |
Correct |
548 ms |
117548 KB |
Output is correct |
7 |
Correct |
9 ms |
19024 KB |
Output is correct |
8 |
Correct |
189 ms |
58912 KB |
Output is correct |
9 |
Correct |
229 ms |
64916 KB |
Output is correct |
10 |
Correct |
111 ms |
49208 KB |
Output is correct |
11 |
Correct |
133 ms |
54136 KB |
Output is correct |
12 |
Correct |
9 ms |
19028 KB |
Output is correct |
13 |
Correct |
10 ms |
19076 KB |
Output is correct |
14 |
Correct |
10 ms |
19028 KB |
Output is correct |
15 |
Correct |
9 ms |
19032 KB |
Output is correct |
16 |
Correct |
40 ms |
36232 KB |
Output is correct |
17 |
Correct |
41 ms |
36200 KB |
Output is correct |
18 |
Correct |
128 ms |
55400 KB |
Output is correct |
19 |
Correct |
160 ms |
61416 KB |
Output is correct |
20 |
Correct |
123 ms |
52356 KB |
Output is correct |
21 |
Correct |
138 ms |
49736 KB |
Output is correct |
22 |
Correct |
129 ms |
52332 KB |
Output is correct |
23 |
Correct |
136 ms |
55696 KB |
Output is correct |
24 |
Correct |
42 ms |
36308 KB |
Output is correct |
25 |
Correct |
41 ms |
36244 KB |
Output is correct |
26 |
Correct |
84 ms |
38584 KB |
Output is correct |
27 |
Correct |
68 ms |
39232 KB |
Output is correct |
28 |
Correct |
146 ms |
43288 KB |
Output is correct |
29 |
Correct |
112 ms |
43340 KB |
Output is correct |
30 |
Correct |
119 ms |
43312 KB |
Output is correct |
31 |
Correct |
117 ms |
43296 KB |
Output is correct |
32 |
Correct |
9 ms |
19028 KB |
Output is correct |
33 |
Correct |
10 ms |
19028 KB |
Output is correct |
34 |
Correct |
10 ms |
19028 KB |
Output is correct |
35 |
Correct |
9 ms |
19092 KB |
Output is correct |
36 |
Correct |
12 ms |
19088 KB |
Output is correct |
37 |
Correct |
9 ms |
19028 KB |
Output is correct |
38 |
Correct |
9 ms |
19028 KB |
Output is correct |
39 |
Correct |
9 ms |
19028 KB |
Output is correct |
40 |
Correct |
10 ms |
19124 KB |
Output is correct |
41 |
Correct |
10 ms |
19448 KB |
Output is correct |
42 |
Correct |
10 ms |
19204 KB |
Output is correct |
43 |
Correct |
10 ms |
19284 KB |
Output is correct |
44 |
Correct |
9 ms |
19024 KB |
Output is correct |
45 |
Correct |
10 ms |
19156 KB |
Output is correct |
46 |
Correct |
9 ms |
19156 KB |
Output is correct |
47 |
Correct |
11 ms |
19384 KB |
Output is correct |
48 |
Correct |
42 ms |
26156 KB |
Output is correct |
49 |
Correct |
41 ms |
25252 KB |
Output is correct |
50 |
Correct |
39 ms |
25464 KB |
Output is correct |
51 |
Correct |
37 ms |
24784 KB |
Output is correct |
52 |
Correct |
39 ms |
24608 KB |
Output is correct |
53 |
Correct |
70 ms |
30284 KB |
Output is correct |
54 |
Correct |
17 ms |
21416 KB |
Output is correct |
55 |
Correct |
35 ms |
25180 KB |
Output is correct |
56 |
Correct |
11 ms |
19284 KB |
Output is correct |
57 |
Correct |
19 ms |
21268 KB |
Output is correct |
58 |
Correct |
13 ms |
20112 KB |
Output is correct |
59 |
Correct |
203 ms |
48624 KB |
Output is correct |
60 |
Correct |
295 ms |
68300 KB |
Output is correct |
61 |
Correct |
381 ms |
108232 KB |
Output is correct |
62 |
Correct |
368 ms |
107352 KB |
Output is correct |
63 |
Correct |
273 ms |
57800 KB |
Output is correct |
64 |
Correct |
374 ms |
109332 KB |
Output is correct |
65 |
Correct |
371 ms |
109276 KB |
Output is correct |
66 |
Correct |
114 ms |
45024 KB |
Output is correct |
67 |
Correct |
359 ms |
93276 KB |
Output is correct |
68 |
Correct |
175 ms |
57432 KB |
Output is correct |
69 |
Correct |
106 ms |
38480 KB |
Output is correct |
70 |
Correct |
230 ms |
57944 KB |
Output is correct |
71 |
Correct |
9 ms |
19028 KB |
Output is correct |
72 |
Correct |
9 ms |
19080 KB |
Output is correct |
73 |
Correct |
9 ms |
19028 KB |
Output is correct |
74 |
Correct |
9 ms |
19092 KB |
Output is correct |
75 |
Correct |
9 ms |
19056 KB |
Output is correct |
76 |
Correct |
10 ms |
19092 KB |
Output is correct |
77 |
Correct |
41 ms |
36296 KB |
Output is correct |
78 |
Correct |
42 ms |
36308 KB |
Output is correct |
79 |
Correct |
41 ms |
36236 KB |
Output is correct |
80 |
Correct |
42 ms |
36216 KB |
Output is correct |
81 |
Correct |
207 ms |
60720 KB |
Output is correct |
82 |
Correct |
271 ms |
72524 KB |
Output is correct |
83 |
Correct |
273 ms |
74344 KB |
Output is correct |
84 |
Correct |
423 ms |
102892 KB |
Output is correct |
85 |
Correct |
410 ms |
110084 KB |
Output is correct |
86 |
Correct |
460 ms |
121560 KB |
Output is correct |
87 |
Correct |
470 ms |
124320 KB |
Output is correct |
88 |
Correct |
10 ms |
19028 KB |
Output is correct |
89 |
Correct |
467 ms |
124228 KB |
Output is correct |
90 |
Correct |
389 ms |
105252 KB |
Output is correct |
91 |
Correct |
308 ms |
84792 KB |
Output is correct |