// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
const ll maxn = 100005;
basic_string<ll> realheights[maxn];
unordered_map<ll, ll> weights;
basic_string<ll> p[maxn];
basic_string<array<ll,2>> dp[maxn];
basic_string<ll> pref[maxn][2];
basic_string<ll> pref2[maxn][2];
basic_string<ll> suff[maxn][2];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
weights.reserve(2097152);
weights.max_load_factor(0.25);
FOR(i,0,M){
Y[i]++;
weights[X[i]*(ll)100000000+Y[i]] = W[i];
if (X[i] > 0) realheights[X[i]-1].push_back(Y[i]);
realheights[X[i]].push_back(Y[i]);
realheights[X[i]+1].push_back(Y[i]);
realheights[X[i]+2].push_back(Y[i]);
}
FOR(i,0,maxn) realheights[i].push_back(0);
FOR(i,0,maxn) realheights[i].push_back(maxn);
FOR(i,0,maxn){
sort(realheights[i].begin(), realheights[i].end());
auto it = unique(realheights[i].begin(), realheights[i].end());
realheights[i].resize(it-realheights[i].begin());
sort(realheights[i].begin(), realheights[i].end());
}
FOR(i,0,maxn){
FOR(k,0,2){
pref[i][k].resize(realheights[i].size());
pref2[i][k].resize(realheights[i].size());
suff[i][k].resize(realheights[i].size());
}
p[i].resize(realheights[i].size());
dp[i].resize(realheights[i].size());
}
FOR(i,0,maxn){
p[i][0] = 0;
ll prev = 0;
FOR(j,1,realheights[i].size()){
p[i][j] = p[i][j-1] + weights[i*(ll)100000000+realheights[i][j]];
}
}
FOR(i,1,N+1){
FOR(X,0,dp[i].size()){
ll j = realheights[i][X];
FOR(k,0,2){
if (i<2) continue;
ll temp = 0;
ll add = 0;
if (k==0){
if (X==dp[i].size()-1) continue;
ll down = upper_bound(realheights[i-1].begin(), realheights[i-1].end(), j) - realheights[i-1].begin() - 1;
temp = max(temp, suff[i-1][0][down] - p[i-1][down]);
temp = max(temp, suff[i-1][1][down] - p[i-1][down]);
// FOR(p,j+1,N+1){
// if (fish[i-1][p]) add += weights[i-1][p];
// temp = max(temp, dp[i-1][p][0] + add);
// temp = max(temp, dp[i-1][p][1] + add);
// }
}
else{
ll down = upper_bound(realheights[i-1].begin(), realheights[i-1].end(), j) - realheights[i-1].begin() - 1;
ll down2 = upper_bound(realheights[i-2].begin(), realheights[i-2].end(), j) - realheights[i-2].begin() - 1;
temp = max(temp, pref[i-1][0][down]);
temp = max(temp, pref[i-1][1][down] + p[i-2][down2]);
// FOR(p,0,j+1) if (fish[i-2][p]) add += weights[i-2][p];
// FOR(p,0,j+1){
// if (fish[i-2][p]) add -= weights[i-2][p];
// temp = max(temp, dp[i-1][p][0]);
// temp = max(temp, dp[i-1][p][1] + add);
// }
}
dp[i][X][k] = temp;
}
}
ll sz = realheights[i].size();
FOR(k,0,2){
ll tempadd = 0;
ll tempadd2 = 0;
FOR(j,0,sz){
tempadd += weights[i*(ll)100000000+realheights[i][j]];
suff[i][k][j] = dp[i][j][k]+tempadd;
}
FOR(j,0,sz){
tempadd2 -= weights[(i-1)*(ll)100000000+realheights[i][j]];
pref[i][k][j] = dp[i][j][k] + tempadd2;
pref2[i][k][j] = dp[i][j][k];
}
ll prev = 0;
FOR(j,1,sz){
pref[i][k][j] = max(pref[i][k][j], pref[i][k][j-1]);
pref2[i][k][j] = max(pref2[i][k][j], pref2[i][k][j-1]);
}
FORNEG(j,sz-2,-1){
suff[i][k][j] = max(suff[i][k][j], suff[i][k][j+1]);
}
}
// cout << i << endl;
// cout << suff[2][2][0] << "FUCK" << endl;
}
ll ans = 0;
FOR(i,0,N+1){
FOR(j,0,dp[i].size()){
ans = max(dp[i][j][0], ans);
ans = max(dp[i][j][1], ans);
}
}
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:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
68 | FOR(j,1,realheights[i].size()){
| ~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:68:9: note: in expansion of macro 'FOR'
68 | FOR(j,1,realheights[i].size()){
| ^~~
fish.cpp:67:12: warning: unused variable 'prev' [-Wunused-variable]
67 | ll prev = 0;
| ^~~~
fish.cpp:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
77 | FOR(X,0,dp[i].size()){
| ~~~~~~~~~~~~~~~~
fish.cpp:77:9: note: in expansion of macro 'FOR'
77 | FOR(X,0,dp[i].size()){
| ^~~
fish.cpp:86:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | if (X==dp[i].size()-1) continue;
| ~^~~~~~~~~~~~~~~~
fish.cpp:84:20: warning: unused variable 'add' [-Wunused-variable]
84 | ll add = 0;
| ^~~
fish.cpp:135:16: warning: unused variable 'prev' [-Wunused-variable]
135 | ll prev = 0;
| ^~~~
fish.cpp:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
162 | FOR(j,0,dp[i].size()){
| ~~~~~~~~~~~~~~~~
fish.cpp:162:9: note: in expansion of macro 'FOR'
162 | FOR(j,0,dp[i].size()){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
111124 KB |
Output is correct |
2 |
Correct |
172 ms |
118120 KB |
Output is correct |
3 |
Correct |
83 ms |
82772 KB |
Output is correct |
4 |
Correct |
82 ms |
82772 KB |
Output is correct |
5 |
Correct |
602 ms |
298320 KB |
Output is correct |
6 |
Correct |
855 ms |
305392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
79784 KB |
Output is correct |
2 |
Correct |
240 ms |
161812 KB |
Output is correct |
3 |
Correct |
283 ms |
165792 KB |
Output is correct |
4 |
Correct |
146 ms |
110896 KB |
Output is correct |
5 |
Correct |
171 ms |
118072 KB |
Output is correct |
6 |
Correct |
58 ms |
79696 KB |
Output is correct |
7 |
Correct |
57 ms |
79700 KB |
Output is correct |
8 |
Correct |
58 ms |
79704 KB |
Output is correct |
9 |
Correct |
57 ms |
79700 KB |
Output is correct |
10 |
Correct |
77 ms |
82772 KB |
Output is correct |
11 |
Correct |
82 ms |
82932 KB |
Output is correct |
12 |
Correct |
171 ms |
119976 KB |
Output is correct |
13 |
Correct |
214 ms |
161312 KB |
Output is correct |
14 |
Correct |
179 ms |
115504 KB |
Output is correct |
15 |
Correct |
168 ms |
107104 KB |
Output is correct |
16 |
Correct |
175 ms |
115620 KB |
Output is correct |
17 |
Correct |
179 ms |
119464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
82768 KB |
Output is correct |
2 |
Correct |
81 ms |
82964 KB |
Output is correct |
3 |
Correct |
122 ms |
96084 KB |
Output is correct |
4 |
Correct |
112 ms |
93064 KB |
Output is correct |
5 |
Correct |
155 ms |
105812 KB |
Output is correct |
6 |
Correct |
165 ms |
105928 KB |
Output is correct |
7 |
Correct |
160 ms |
105796 KB |
Output is correct |
8 |
Correct |
152 ms |
105828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
79696 KB |
Output is correct |
2 |
Correct |
60 ms |
79700 KB |
Output is correct |
3 |
Correct |
64 ms |
79804 KB |
Output is correct |
4 |
Correct |
70 ms |
79660 KB |
Output is correct |
5 |
Correct |
55 ms |
79652 KB |
Output is correct |
6 |
Correct |
58 ms |
79628 KB |
Output is correct |
7 |
Correct |
58 ms |
79768 KB |
Output is correct |
8 |
Correct |
57 ms |
79700 KB |
Output is correct |
9 |
Correct |
74 ms |
79768 KB |
Output is correct |
10 |
Correct |
67 ms |
80212 KB |
Output is correct |
11 |
Correct |
74 ms |
79872 KB |
Output is correct |
12 |
Correct |
58 ms |
79956 KB |
Output is correct |
13 |
Correct |
57 ms |
79696 KB |
Output is correct |
14 |
Correct |
57 ms |
79956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
79696 KB |
Output is correct |
2 |
Correct |
60 ms |
79700 KB |
Output is correct |
3 |
Correct |
64 ms |
79804 KB |
Output is correct |
4 |
Correct |
70 ms |
79660 KB |
Output is correct |
5 |
Correct |
55 ms |
79652 KB |
Output is correct |
6 |
Correct |
58 ms |
79628 KB |
Output is correct |
7 |
Correct |
58 ms |
79768 KB |
Output is correct |
8 |
Correct |
57 ms |
79700 KB |
Output is correct |
9 |
Correct |
74 ms |
79768 KB |
Output is correct |
10 |
Correct |
67 ms |
80212 KB |
Output is correct |
11 |
Correct |
74 ms |
79872 KB |
Output is correct |
12 |
Correct |
58 ms |
79956 KB |
Output is correct |
13 |
Correct |
57 ms |
79696 KB |
Output is correct |
14 |
Correct |
57 ms |
79956 KB |
Output is correct |
15 |
Correct |
58 ms |
79888 KB |
Output is correct |
16 |
Correct |
74 ms |
80212 KB |
Output is correct |
17 |
Correct |
102 ms |
89168 KB |
Output is correct |
18 |
Correct |
93 ms |
88432 KB |
Output is correct |
19 |
Correct |
116 ms |
89168 KB |
Output is correct |
20 |
Correct |
93 ms |
87888 KB |
Output is correct |
21 |
Correct |
91 ms |
87888 KB |
Output is correct |
22 |
Correct |
119 ms |
95516 KB |
Output is correct |
23 |
Correct |
81 ms |
83752 KB |
Output is correct |
24 |
Correct |
99 ms |
89344 KB |
Output is correct |
25 |
Correct |
67 ms |
80212 KB |
Output is correct |
26 |
Correct |
83 ms |
82808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
79696 KB |
Output is correct |
2 |
Correct |
60 ms |
79700 KB |
Output is correct |
3 |
Correct |
64 ms |
79804 KB |
Output is correct |
4 |
Correct |
70 ms |
79660 KB |
Output is correct |
5 |
Correct |
55 ms |
79652 KB |
Output is correct |
6 |
Correct |
58 ms |
79628 KB |
Output is correct |
7 |
Correct |
58 ms |
79768 KB |
Output is correct |
8 |
Correct |
57 ms |
79700 KB |
Output is correct |
9 |
Correct |
74 ms |
79768 KB |
Output is correct |
10 |
Correct |
67 ms |
80212 KB |
Output is correct |
11 |
Correct |
74 ms |
79872 KB |
Output is correct |
12 |
Correct |
58 ms |
79956 KB |
Output is correct |
13 |
Correct |
57 ms |
79696 KB |
Output is correct |
14 |
Correct |
57 ms |
79956 KB |
Output is correct |
15 |
Correct |
58 ms |
79888 KB |
Output is correct |
16 |
Correct |
74 ms |
80212 KB |
Output is correct |
17 |
Correct |
102 ms |
89168 KB |
Output is correct |
18 |
Correct |
93 ms |
88432 KB |
Output is correct |
19 |
Correct |
116 ms |
89168 KB |
Output is correct |
20 |
Correct |
93 ms |
87888 KB |
Output is correct |
21 |
Correct |
91 ms |
87888 KB |
Output is correct |
22 |
Correct |
119 ms |
95516 KB |
Output is correct |
23 |
Correct |
81 ms |
83752 KB |
Output is correct |
24 |
Correct |
99 ms |
89344 KB |
Output is correct |
25 |
Correct |
67 ms |
80212 KB |
Output is correct |
26 |
Correct |
83 ms |
82808 KB |
Output is correct |
27 |
Correct |
80 ms |
81236 KB |
Output is correct |
28 |
Correct |
234 ms |
122304 KB |
Output is correct |
29 |
Correct |
375 ms |
185940 KB |
Output is correct |
30 |
Correct |
594 ms |
294360 KB |
Output is correct |
31 |
Correct |
592 ms |
292888 KB |
Output is correct |
32 |
Correct |
253 ms |
130960 KB |
Output is correct |
33 |
Correct |
630 ms |
296928 KB |
Output is correct |
34 |
Correct |
609 ms |
296984 KB |
Output is correct |
35 |
Correct |
174 ms |
119124 KB |
Output is correct |
36 |
Correct |
485 ms |
280072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
82768 KB |
Output is correct |
2 |
Correct |
81 ms |
82964 KB |
Output is correct |
3 |
Correct |
122 ms |
96084 KB |
Output is correct |
4 |
Correct |
112 ms |
93064 KB |
Output is correct |
5 |
Correct |
155 ms |
105812 KB |
Output is correct |
6 |
Correct |
165 ms |
105928 KB |
Output is correct |
7 |
Correct |
160 ms |
105796 KB |
Output is correct |
8 |
Correct |
152 ms |
105828 KB |
Output is correct |
9 |
Correct |
303 ms |
163156 KB |
Output is correct |
10 |
Correct |
175 ms |
99924 KB |
Output is correct |
11 |
Correct |
253 ms |
120060 KB |
Output is correct |
12 |
Correct |
69 ms |
79700 KB |
Output is correct |
13 |
Correct |
72 ms |
79816 KB |
Output is correct |
14 |
Correct |
59 ms |
79724 KB |
Output is correct |
15 |
Correct |
58 ms |
79696 KB |
Output is correct |
16 |
Correct |
62 ms |
79660 KB |
Output is correct |
17 |
Correct |
57 ms |
79660 KB |
Output is correct |
18 |
Correct |
86 ms |
82948 KB |
Output is correct |
19 |
Correct |
85 ms |
82768 KB |
Output is correct |
20 |
Correct |
84 ms |
82772 KB |
Output is correct |
21 |
Correct |
89 ms |
82732 KB |
Output is correct |
22 |
Correct |
337 ms |
165204 KB |
Output is correct |
23 |
Correct |
417 ms |
178768 KB |
Output is correct |
24 |
Correct |
484 ms |
182352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
111124 KB |
Output is correct |
2 |
Correct |
172 ms |
118120 KB |
Output is correct |
3 |
Correct |
83 ms |
82772 KB |
Output is correct |
4 |
Correct |
82 ms |
82772 KB |
Output is correct |
5 |
Correct |
602 ms |
298320 KB |
Output is correct |
6 |
Correct |
855 ms |
305392 KB |
Output is correct |
7 |
Correct |
60 ms |
79784 KB |
Output is correct |
8 |
Correct |
240 ms |
161812 KB |
Output is correct |
9 |
Correct |
283 ms |
165792 KB |
Output is correct |
10 |
Correct |
146 ms |
110896 KB |
Output is correct |
11 |
Correct |
171 ms |
118072 KB |
Output is correct |
12 |
Correct |
58 ms |
79696 KB |
Output is correct |
13 |
Correct |
57 ms |
79700 KB |
Output is correct |
14 |
Correct |
58 ms |
79704 KB |
Output is correct |
15 |
Correct |
57 ms |
79700 KB |
Output is correct |
16 |
Correct |
77 ms |
82772 KB |
Output is correct |
17 |
Correct |
82 ms |
82932 KB |
Output is correct |
18 |
Correct |
171 ms |
119976 KB |
Output is correct |
19 |
Correct |
214 ms |
161312 KB |
Output is correct |
20 |
Correct |
179 ms |
115504 KB |
Output is correct |
21 |
Correct |
168 ms |
107104 KB |
Output is correct |
22 |
Correct |
175 ms |
115620 KB |
Output is correct |
23 |
Correct |
179 ms |
119464 KB |
Output is correct |
24 |
Correct |
87 ms |
82768 KB |
Output is correct |
25 |
Correct |
81 ms |
82964 KB |
Output is correct |
26 |
Correct |
122 ms |
96084 KB |
Output is correct |
27 |
Correct |
112 ms |
93064 KB |
Output is correct |
28 |
Correct |
155 ms |
105812 KB |
Output is correct |
29 |
Correct |
165 ms |
105928 KB |
Output is correct |
30 |
Correct |
160 ms |
105796 KB |
Output is correct |
31 |
Correct |
152 ms |
105828 KB |
Output is correct |
32 |
Correct |
70 ms |
79696 KB |
Output is correct |
33 |
Correct |
60 ms |
79700 KB |
Output is correct |
34 |
Correct |
64 ms |
79804 KB |
Output is correct |
35 |
Correct |
70 ms |
79660 KB |
Output is correct |
36 |
Correct |
55 ms |
79652 KB |
Output is correct |
37 |
Correct |
58 ms |
79628 KB |
Output is correct |
38 |
Correct |
58 ms |
79768 KB |
Output is correct |
39 |
Correct |
57 ms |
79700 KB |
Output is correct |
40 |
Correct |
74 ms |
79768 KB |
Output is correct |
41 |
Correct |
67 ms |
80212 KB |
Output is correct |
42 |
Correct |
74 ms |
79872 KB |
Output is correct |
43 |
Correct |
58 ms |
79956 KB |
Output is correct |
44 |
Correct |
57 ms |
79696 KB |
Output is correct |
45 |
Correct |
57 ms |
79956 KB |
Output is correct |
46 |
Correct |
58 ms |
79888 KB |
Output is correct |
47 |
Correct |
74 ms |
80212 KB |
Output is correct |
48 |
Correct |
102 ms |
89168 KB |
Output is correct |
49 |
Correct |
93 ms |
88432 KB |
Output is correct |
50 |
Correct |
116 ms |
89168 KB |
Output is correct |
51 |
Correct |
93 ms |
87888 KB |
Output is correct |
52 |
Correct |
91 ms |
87888 KB |
Output is correct |
53 |
Correct |
119 ms |
95516 KB |
Output is correct |
54 |
Correct |
81 ms |
83752 KB |
Output is correct |
55 |
Correct |
99 ms |
89344 KB |
Output is correct |
56 |
Correct |
67 ms |
80212 KB |
Output is correct |
57 |
Correct |
83 ms |
82808 KB |
Output is correct |
58 |
Correct |
80 ms |
81236 KB |
Output is correct |
59 |
Correct |
234 ms |
122304 KB |
Output is correct |
60 |
Correct |
375 ms |
185940 KB |
Output is correct |
61 |
Correct |
594 ms |
294360 KB |
Output is correct |
62 |
Correct |
592 ms |
292888 KB |
Output is correct |
63 |
Correct |
253 ms |
130960 KB |
Output is correct |
64 |
Correct |
630 ms |
296928 KB |
Output is correct |
65 |
Correct |
609 ms |
296984 KB |
Output is correct |
66 |
Correct |
174 ms |
119124 KB |
Output is correct |
67 |
Correct |
485 ms |
280072 KB |
Output is correct |
68 |
Correct |
303 ms |
163156 KB |
Output is correct |
69 |
Correct |
175 ms |
99924 KB |
Output is correct |
70 |
Correct |
253 ms |
120060 KB |
Output is correct |
71 |
Correct |
69 ms |
79700 KB |
Output is correct |
72 |
Correct |
72 ms |
79816 KB |
Output is correct |
73 |
Correct |
59 ms |
79724 KB |
Output is correct |
74 |
Correct |
58 ms |
79696 KB |
Output is correct |
75 |
Correct |
62 ms |
79660 KB |
Output is correct |
76 |
Correct |
57 ms |
79660 KB |
Output is correct |
77 |
Correct |
86 ms |
82948 KB |
Output is correct |
78 |
Correct |
85 ms |
82768 KB |
Output is correct |
79 |
Correct |
84 ms |
82772 KB |
Output is correct |
80 |
Correct |
89 ms |
82732 KB |
Output is correct |
81 |
Correct |
337 ms |
165204 KB |
Output is correct |
82 |
Correct |
417 ms |
178768 KB |
Output is correct |
83 |
Correct |
484 ms |
182352 KB |
Output is correct |
84 |
Correct |
595 ms |
290280 KB |
Output is correct |
85 |
Correct |
564 ms |
288776 KB |
Output is correct |
86 |
Correct |
923 ms |
311516 KB |
Output is correct |
87 |
Correct |
938 ms |
312792 KB |
Output is correct |
88 |
Correct |
57 ms |
79708 KB |
Output is correct |
89 |
Correct |
960 ms |
313052 KB |
Output is correct |
90 |
Correct |
457 ms |
210168 KB |
Output is correct |
91 |
Correct |
347 ms |
183288 KB |
Output is correct |