# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
831206 |
2023-08-19T22:17:50 Z |
Wael |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
169932 KB |
#include <bits/stdc++.h>
using namespace std;
#include "fish.h"
int const Mx = 1e5 + 10;
long long n , m;
map<int , int>cost[Mx] , vis[Mx];
vector<int>possible[Mx];
vector<long long>pref[Mx] , dp[3][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];
if(vis[X[i] - 1][Y[i]] == 0) possible[X[i] - 1].push_back(Y[i]);
if(vis[X[i] + 1][Y[i]] == 0) possible[X[i] + 1].push_back(Y[i]);
if(vis[X[i]][Y[i]] == 0) possible[X[i]].push_back(Y[i]);
vis[X[i] - 1][Y[i]] = 1;
vis[X[i] + 1][Y[i]] = 1;
vis[X[i]][Y[i]] = 1;
cost[X[i]][Y[i]] = W[i];
}
for(int i = 1 ; i <= n + 1 ; ++i) {
possible[i].push_back(0);
sort(possible[i].begin() , possible[i].end());
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) {
int Req = 0 , ReqNext = 0;
for(int J = 0 ; J < possible[i].size() ; ++J) {
int 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) {
int 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) {
int 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 |
201 ms |
64304 KB |
Output is correct |
2 |
Correct |
257 ms |
72364 KB |
Output is correct |
3 |
Correct |
40 ms |
38612 KB |
Output is correct |
4 |
Correct |
39 ms |
38592 KB |
Output is correct |
5 |
Correct |
889 ms |
163000 KB |
Output is correct |
6 |
Correct |
804 ms |
169932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21332 KB |
Output is correct |
2 |
Correct |
401 ms |
79484 KB |
Output is correct |
3 |
Correct |
519 ms |
88724 KB |
Output is correct |
4 |
Correct |
205 ms |
64292 KB |
Output is correct |
5 |
Correct |
259 ms |
72332 KB |
Output is correct |
6 |
Correct |
14 ms |
21332 KB |
Output is correct |
7 |
Correct |
13 ms |
21440 KB |
Output is correct |
8 |
Correct |
10 ms |
21332 KB |
Output is correct |
9 |
Correct |
11 ms |
21332 KB |
Output is correct |
10 |
Correct |
39 ms |
38648 KB |
Output is correct |
11 |
Correct |
40 ms |
38644 KB |
Output is correct |
12 |
Correct |
227 ms |
70088 KB |
Output is correct |
13 |
Correct |
286 ms |
79436 KB |
Output is correct |
14 |
Correct |
216 ms |
67432 KB |
Output is correct |
15 |
Correct |
210 ms |
62212 KB |
Output is correct |
16 |
Correct |
215 ms |
67536 KB |
Output is correct |
17 |
Correct |
241 ms |
72404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
38540 KB |
Output is correct |
2 |
Correct |
39 ms |
38640 KB |
Output is correct |
3 |
Correct |
90 ms |
44632 KB |
Output is correct |
4 |
Correct |
74 ms |
44300 KB |
Output is correct |
5 |
Correct |
134 ms |
52012 KB |
Output is correct |
6 |
Correct |
128 ms |
51272 KB |
Output is correct |
7 |
Correct |
141 ms |
51868 KB |
Output is correct |
8 |
Correct |
175 ms |
52024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21332 KB |
Output is correct |
2 |
Correct |
11 ms |
21352 KB |
Output is correct |
3 |
Correct |
11 ms |
21432 KB |
Output is correct |
4 |
Correct |
10 ms |
21332 KB |
Output is correct |
5 |
Correct |
11 ms |
21332 KB |
Output is correct |
6 |
Correct |
10 ms |
21440 KB |
Output is correct |
7 |
Correct |
17 ms |
21376 KB |
Output is correct |
8 |
Correct |
10 ms |
21436 KB |
Output is correct |
9 |
Correct |
11 ms |
21448 KB |
Output is correct |
10 |
Correct |
11 ms |
21844 KB |
Output is correct |
11 |
Correct |
11 ms |
21576 KB |
Output is correct |
12 |
Correct |
11 ms |
21704 KB |
Output is correct |
13 |
Correct |
10 ms |
21408 KB |
Output is correct |
14 |
Correct |
11 ms |
21696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21332 KB |
Output is correct |
2 |
Correct |
11 ms |
21352 KB |
Output is correct |
3 |
Correct |
11 ms |
21432 KB |
Output is correct |
4 |
Correct |
10 ms |
21332 KB |
Output is correct |
5 |
Correct |
11 ms |
21332 KB |
Output is correct |
6 |
Correct |
10 ms |
21440 KB |
Output is correct |
7 |
Correct |
17 ms |
21376 KB |
Output is correct |
8 |
Correct |
10 ms |
21436 KB |
Output is correct |
9 |
Correct |
11 ms |
21448 KB |
Output is correct |
10 |
Correct |
11 ms |
21844 KB |
Output is correct |
11 |
Correct |
11 ms |
21576 KB |
Output is correct |
12 |
Correct |
11 ms |
21704 KB |
Output is correct |
13 |
Correct |
10 ms |
21408 KB |
Output is correct |
14 |
Correct |
11 ms |
21696 KB |
Output is correct |
15 |
Correct |
11 ms |
21552 KB |
Output is correct |
16 |
Correct |
13 ms |
21844 KB |
Output is correct |
17 |
Correct |
68 ms |
31824 KB |
Output is correct |
18 |
Correct |
63 ms |
30524 KB |
Output is correct |
19 |
Correct |
60 ms |
30820 KB |
Output is correct |
20 |
Correct |
61 ms |
29712 KB |
Output is correct |
21 |
Correct |
58 ms |
29632 KB |
Output is correct |
22 |
Correct |
124 ms |
37728 KB |
Output is correct |
23 |
Correct |
24 ms |
25100 KB |
Output is correct |
24 |
Correct |
54 ms |
30648 KB |
Output is correct |
25 |
Correct |
12 ms |
21868 KB |
Output is correct |
26 |
Correct |
22 ms |
24596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21332 KB |
Output is correct |
2 |
Correct |
11 ms |
21352 KB |
Output is correct |
3 |
Correct |
11 ms |
21432 KB |
Output is correct |
4 |
Correct |
10 ms |
21332 KB |
Output is correct |
5 |
Correct |
11 ms |
21332 KB |
Output is correct |
6 |
Correct |
10 ms |
21440 KB |
Output is correct |
7 |
Correct |
17 ms |
21376 KB |
Output is correct |
8 |
Correct |
10 ms |
21436 KB |
Output is correct |
9 |
Correct |
11 ms |
21448 KB |
Output is correct |
10 |
Correct |
11 ms |
21844 KB |
Output is correct |
11 |
Correct |
11 ms |
21576 KB |
Output is correct |
12 |
Correct |
11 ms |
21704 KB |
Output is correct |
13 |
Correct |
10 ms |
21408 KB |
Output is correct |
14 |
Correct |
11 ms |
21696 KB |
Output is correct |
15 |
Correct |
11 ms |
21552 KB |
Output is correct |
16 |
Correct |
13 ms |
21844 KB |
Output is correct |
17 |
Correct |
68 ms |
31824 KB |
Output is correct |
18 |
Correct |
63 ms |
30524 KB |
Output is correct |
19 |
Correct |
60 ms |
30820 KB |
Output is correct |
20 |
Correct |
61 ms |
29712 KB |
Output is correct |
21 |
Correct |
58 ms |
29632 KB |
Output is correct |
22 |
Correct |
124 ms |
37728 KB |
Output is correct |
23 |
Correct |
24 ms |
25100 KB |
Output is correct |
24 |
Correct |
54 ms |
30648 KB |
Output is correct |
25 |
Correct |
12 ms |
21868 KB |
Output is correct |
26 |
Correct |
22 ms |
24596 KB |
Output is correct |
27 |
Correct |
14 ms |
22988 KB |
Output is correct |
28 |
Correct |
422 ms |
66316 KB |
Output is correct |
29 |
Correct |
751 ms |
97360 KB |
Output is correct |
30 |
Correct |
935 ms |
156164 KB |
Output is correct |
31 |
Correct |
875 ms |
154832 KB |
Output is correct |
32 |
Correct |
541 ms |
77276 KB |
Output is correct |
33 |
Correct |
969 ms |
158364 KB |
Output is correct |
34 |
Correct |
897 ms |
158236 KB |
Output is correct |
35 |
Correct |
226 ms |
61004 KB |
Output is correct |
36 |
Correct |
845 ms |
135404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
38540 KB |
Output is correct |
2 |
Correct |
39 ms |
38640 KB |
Output is correct |
3 |
Correct |
90 ms |
44632 KB |
Output is correct |
4 |
Correct |
74 ms |
44300 KB |
Output is correct |
5 |
Correct |
134 ms |
52012 KB |
Output is correct |
6 |
Correct |
128 ms |
51272 KB |
Output is correct |
7 |
Correct |
141 ms |
51868 KB |
Output is correct |
8 |
Correct |
175 ms |
52024 KB |
Output is correct |
9 |
Correct |
222 ms |
75232 KB |
Output is correct |
10 |
Correct |
113 ms |
45848 KB |
Output is correct |
11 |
Correct |
272 ms |
70244 KB |
Output is correct |
12 |
Correct |
10 ms |
21332 KB |
Output is correct |
13 |
Correct |
11 ms |
21332 KB |
Output is correct |
14 |
Correct |
11 ms |
21332 KB |
Output is correct |
15 |
Correct |
10 ms |
21436 KB |
Output is correct |
16 |
Correct |
10 ms |
21404 KB |
Output is correct |
17 |
Correct |
10 ms |
21332 KB |
Output is correct |
18 |
Correct |
36 ms |
38604 KB |
Output is correct |
19 |
Correct |
37 ms |
38592 KB |
Output is correct |
20 |
Correct |
39 ms |
38636 KB |
Output is correct |
21 |
Correct |
39 ms |
38604 KB |
Output is correct |
22 |
Correct |
263 ms |
79284 KB |
Output is correct |
23 |
Correct |
385 ms |
96432 KB |
Output is correct |
24 |
Correct |
406 ms |
100176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
64304 KB |
Output is correct |
2 |
Correct |
257 ms |
72364 KB |
Output is correct |
3 |
Correct |
40 ms |
38612 KB |
Output is correct |
4 |
Correct |
39 ms |
38592 KB |
Output is correct |
5 |
Correct |
889 ms |
163000 KB |
Output is correct |
6 |
Correct |
804 ms |
169932 KB |
Output is correct |
7 |
Correct |
11 ms |
21332 KB |
Output is correct |
8 |
Correct |
401 ms |
79484 KB |
Output is correct |
9 |
Correct |
519 ms |
88724 KB |
Output is correct |
10 |
Correct |
205 ms |
64292 KB |
Output is correct |
11 |
Correct |
259 ms |
72332 KB |
Output is correct |
12 |
Correct |
14 ms |
21332 KB |
Output is correct |
13 |
Correct |
13 ms |
21440 KB |
Output is correct |
14 |
Correct |
10 ms |
21332 KB |
Output is correct |
15 |
Correct |
11 ms |
21332 KB |
Output is correct |
16 |
Correct |
39 ms |
38648 KB |
Output is correct |
17 |
Correct |
40 ms |
38644 KB |
Output is correct |
18 |
Correct |
227 ms |
70088 KB |
Output is correct |
19 |
Correct |
286 ms |
79436 KB |
Output is correct |
20 |
Correct |
216 ms |
67432 KB |
Output is correct |
21 |
Correct |
210 ms |
62212 KB |
Output is correct |
22 |
Correct |
215 ms |
67536 KB |
Output is correct |
23 |
Correct |
241 ms |
72404 KB |
Output is correct |
24 |
Correct |
38 ms |
38540 KB |
Output is correct |
25 |
Correct |
39 ms |
38640 KB |
Output is correct |
26 |
Correct |
90 ms |
44632 KB |
Output is correct |
27 |
Correct |
74 ms |
44300 KB |
Output is correct |
28 |
Correct |
134 ms |
52012 KB |
Output is correct |
29 |
Correct |
128 ms |
51272 KB |
Output is correct |
30 |
Correct |
141 ms |
51868 KB |
Output is correct |
31 |
Correct |
175 ms |
52024 KB |
Output is correct |
32 |
Correct |
11 ms |
21332 KB |
Output is correct |
33 |
Correct |
11 ms |
21352 KB |
Output is correct |
34 |
Correct |
11 ms |
21432 KB |
Output is correct |
35 |
Correct |
10 ms |
21332 KB |
Output is correct |
36 |
Correct |
11 ms |
21332 KB |
Output is correct |
37 |
Correct |
10 ms |
21440 KB |
Output is correct |
38 |
Correct |
17 ms |
21376 KB |
Output is correct |
39 |
Correct |
10 ms |
21436 KB |
Output is correct |
40 |
Correct |
11 ms |
21448 KB |
Output is correct |
41 |
Correct |
11 ms |
21844 KB |
Output is correct |
42 |
Correct |
11 ms |
21576 KB |
Output is correct |
43 |
Correct |
11 ms |
21704 KB |
Output is correct |
44 |
Correct |
10 ms |
21408 KB |
Output is correct |
45 |
Correct |
11 ms |
21696 KB |
Output is correct |
46 |
Correct |
11 ms |
21552 KB |
Output is correct |
47 |
Correct |
13 ms |
21844 KB |
Output is correct |
48 |
Correct |
68 ms |
31824 KB |
Output is correct |
49 |
Correct |
63 ms |
30524 KB |
Output is correct |
50 |
Correct |
60 ms |
30820 KB |
Output is correct |
51 |
Correct |
61 ms |
29712 KB |
Output is correct |
52 |
Correct |
58 ms |
29632 KB |
Output is correct |
53 |
Correct |
124 ms |
37728 KB |
Output is correct |
54 |
Correct |
24 ms |
25100 KB |
Output is correct |
55 |
Correct |
54 ms |
30648 KB |
Output is correct |
56 |
Correct |
12 ms |
21868 KB |
Output is correct |
57 |
Correct |
22 ms |
24596 KB |
Output is correct |
58 |
Correct |
14 ms |
22988 KB |
Output is correct |
59 |
Correct |
422 ms |
66316 KB |
Output is correct |
60 |
Correct |
751 ms |
97360 KB |
Output is correct |
61 |
Correct |
935 ms |
156164 KB |
Output is correct |
62 |
Correct |
875 ms |
154832 KB |
Output is correct |
63 |
Correct |
541 ms |
77276 KB |
Output is correct |
64 |
Correct |
969 ms |
158364 KB |
Output is correct |
65 |
Correct |
897 ms |
158236 KB |
Output is correct |
66 |
Correct |
226 ms |
61004 KB |
Output is correct |
67 |
Correct |
845 ms |
135404 KB |
Output is correct |
68 |
Correct |
222 ms |
75232 KB |
Output is correct |
69 |
Correct |
113 ms |
45848 KB |
Output is correct |
70 |
Correct |
272 ms |
70244 KB |
Output is correct |
71 |
Correct |
10 ms |
21332 KB |
Output is correct |
72 |
Correct |
11 ms |
21332 KB |
Output is correct |
73 |
Correct |
11 ms |
21332 KB |
Output is correct |
74 |
Correct |
10 ms |
21436 KB |
Output is correct |
75 |
Correct |
10 ms |
21404 KB |
Output is correct |
76 |
Correct |
10 ms |
21332 KB |
Output is correct |
77 |
Correct |
36 ms |
38604 KB |
Output is correct |
78 |
Correct |
37 ms |
38592 KB |
Output is correct |
79 |
Correct |
39 ms |
38636 KB |
Output is correct |
80 |
Correct |
39 ms |
38604 KB |
Output is correct |
81 |
Correct |
263 ms |
79284 KB |
Output is correct |
82 |
Correct |
385 ms |
96432 KB |
Output is correct |
83 |
Correct |
406 ms |
100176 KB |
Output is correct |
84 |
Execution timed out |
1033 ms |
147368 KB |
Time limit exceeded |
85 |
Halted |
0 ms |
0 KB |
- |