// #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;
set<ll> heights[maxn];
vector<ll> realheights[maxn];
unordered_map<ll,ll> fish[maxn];
unordered_map<ll,ll> weights[maxn];
unordered_map<ll,ll> p[maxn];
vector<array<ll,2>> dp[maxn];
unordered_map<ll,ll> pref[maxn][2];
unordered_map<ll,ll> pref2[maxn][2];
unordered_map<ll,ll> suff[maxn][2];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
FOR(i,0,M){
Y[i]++;
fish[X[i]][Y[i]] = 1;
weights[X[i]][Y[i]] = W[i];
if (X[i] > 0) heights[X[i]-1].insert(Y[i]);
if (X[i] > 1) heights[X[i]-2].insert(Y[i]);
heights[X[i]].insert(Y[i]);
heights[X[i]+1].insert(Y[i]);
heights[X[i]+2].insert(Y[i]);
}
FOR(i,0,maxn) heights[i].insert(0);
FOR(i,0,maxn) heights[i].insert(maxn);
FOR(i,0,maxn){
p[i][0] = 0;
ll prev = 0;
for (auto j : heights[i]){
if (j==0) continue;
p[i][j] = p[i][prev] + weights[i][j];
prev = j;
}
}
FOR(i,0,maxn){
for (auto k : heights[i]) realheights[i].push_back(k);
}
FOR(i,0,maxn){
dp[i].resize(heights[i].size());
}
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 up = *upper_bound(realheights[i-1].begin(), realheights[i-1].end(), realheights[i][X]);
ll down = *(--upper_bound(realheights[i-1].begin(), realheights[i-1].end(), realheights[i][X]));
temp = max(temp, suff[i-1][0][up] - p[i-1][down]);
temp = max(temp, suff[i-1][1][up] - 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(), realheights[i][X]));
ll down2 = *(--upper_bound(realheights[i-2].begin(), realheights[i-2].end(), realheights[i][X]));
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][realheights[i][j]];
suff[i][k][realheights[i][j]] = dp[i][j][k]+tempadd;
}
FOR(j,0,sz){
tempadd2 -= weights[i-1][realheights[i][j]];
pref[i][k][realheights[i][j]] = dp[i][j][k] + tempadd2;
pref2[i][k][realheights[i][j]] = dp[i][j][k];
}
ll prev = 0;
FOR(j,1,sz){
pref[i][k][realheights[i][j]] = max(pref[i][k][realheights[i][j]], pref[i][k][prev]);
pref2[i][k][realheights[i][j]] = max(pref2[i][k][realheights[i][j]], pref2[i][k][prev]);
prev = realheights[i][j];
}
prev = realheights[i][sz-1];
FORNEG(j,sz-2,-1){
suff[i][k][realheights[i][j]] = max(suff[i][k][realheights[i][j]], suff[i][k][prev]);
prev = realheights[i][j];
}
}
// cout << i << endl;
// cout << suff[2][2][0] << "FUCK" << endl;
}
// cout << dp[3][2][0] << 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::vector<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++)
......
65 | FOR(X,0,dp[i].size()){
| ~~~~~~~~~~~~~~~~
fish.cpp:65:9: note: in expansion of macro 'FOR'
65 | FOR(X,0,dp[i].size()){
| ^~~
fish.cpp:74:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if (X==dp[i].size()-1) continue;
| ~^~~~~~~~~~~~~~~~
fish.cpp:72:20: warning: unused variable 'add' [-Wunused-variable]
72 | ll add = 0;
| ^~~
fish.cpp:66:16: warning: unused variable 'j' [-Wunused-variable]
66 | ll j = realheights[i][X];
| ^
fish.cpp:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<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++)
......
148 | FOR(j,0,dp[i].size()){
| ~~~~~~~~~~~~~~~~
fish.cpp:148:9: note: in expansion of macro 'FOR'
148 | FOR(j,0,dp[i].size()){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
488 ms |
283172 KB |
Output is correct |
2 |
Correct |
708 ms |
324600 KB |
Output is correct |
3 |
Correct |
257 ms |
214096 KB |
Output is correct |
4 |
Correct |
302 ms |
214096 KB |
Output is correct |
5 |
Execution timed out |
1056 ms |
346576 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
107604 KB |
Output is correct |
2 |
Correct |
937 ms |
338188 KB |
Output is correct |
3 |
Correct |
978 ms |
375976 KB |
Output is correct |
4 |
Correct |
484 ms |
284528 KB |
Output is correct |
5 |
Correct |
637 ms |
324444 KB |
Output is correct |
6 |
Correct |
72 ms |
107856 KB |
Output is correct |
7 |
Correct |
84 ms |
107604 KB |
Output is correct |
8 |
Correct |
84 ms |
107616 KB |
Output is correct |
9 |
Correct |
98 ms |
107600 KB |
Output is correct |
10 |
Correct |
300 ms |
214100 KB |
Output is correct |
11 |
Correct |
330 ms |
214016 KB |
Output is correct |
12 |
Correct |
598 ms |
316388 KB |
Output is correct |
13 |
Correct |
806 ms |
367416 KB |
Output is correct |
14 |
Correct |
686 ms |
300324 KB |
Output is correct |
15 |
Correct |
591 ms |
292180 KB |
Output is correct |
16 |
Correct |
695 ms |
300504 KB |
Output is correct |
17 |
Correct |
802 ms |
336016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
323 ms |
214104 KB |
Output is correct |
2 |
Correct |
305 ms |
214100 KB |
Output is correct |
3 |
Correct |
407 ms |
232792 KB |
Output is correct |
4 |
Correct |
334 ms |
237104 KB |
Output is correct |
5 |
Correct |
503 ms |
264972 KB |
Output is correct |
6 |
Correct |
456 ms |
264200 KB |
Output is correct |
7 |
Correct |
520 ms |
264788 KB |
Output is correct |
8 |
Correct |
554 ms |
264840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
107604 KB |
Output is correct |
2 |
Correct |
101 ms |
107600 KB |
Output is correct |
3 |
Correct |
81 ms |
107600 KB |
Output is correct |
4 |
Correct |
101 ms |
107436 KB |
Output is correct |
5 |
Correct |
75 ms |
107604 KB |
Output is correct |
6 |
Correct |
99 ms |
107452 KB |
Output is correct |
7 |
Correct |
101 ms |
107600 KB |
Output is correct |
8 |
Correct |
78 ms |
107472 KB |
Output is correct |
9 |
Correct |
80 ms |
107860 KB |
Output is correct |
10 |
Correct |
92 ms |
108700 KB |
Output is correct |
11 |
Correct |
88 ms |
108136 KB |
Output is correct |
12 |
Correct |
87 ms |
108724 KB |
Output is correct |
13 |
Correct |
94 ms |
107744 KB |
Output is correct |
14 |
Correct |
93 ms |
108332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
107604 KB |
Output is correct |
2 |
Correct |
101 ms |
107600 KB |
Output is correct |
3 |
Correct |
81 ms |
107600 KB |
Output is correct |
4 |
Correct |
101 ms |
107436 KB |
Output is correct |
5 |
Correct |
75 ms |
107604 KB |
Output is correct |
6 |
Correct |
99 ms |
107452 KB |
Output is correct |
7 |
Correct |
101 ms |
107600 KB |
Output is correct |
8 |
Correct |
78 ms |
107472 KB |
Output is correct |
9 |
Correct |
80 ms |
107860 KB |
Output is correct |
10 |
Correct |
92 ms |
108700 KB |
Output is correct |
11 |
Correct |
88 ms |
108136 KB |
Output is correct |
12 |
Correct |
87 ms |
108724 KB |
Output is correct |
13 |
Correct |
94 ms |
107744 KB |
Output is correct |
14 |
Correct |
93 ms |
108332 KB |
Output is correct |
15 |
Correct |
111 ms |
108484 KB |
Output is correct |
16 |
Correct |
103 ms |
109256 KB |
Output is correct |
17 |
Correct |
245 ms |
140112 KB |
Output is correct |
18 |
Correct |
201 ms |
134224 KB |
Output is correct |
19 |
Correct |
190 ms |
138320 KB |
Output is correct |
20 |
Correct |
184 ms |
131156 KB |
Output is correct |
21 |
Correct |
208 ms |
130388 KB |
Output is correct |
22 |
Correct |
260 ms |
153428 KB |
Output is correct |
23 |
Correct |
150 ms |
123796 KB |
Output is correct |
24 |
Correct |
246 ms |
144496 KB |
Output is correct |
25 |
Correct |
96 ms |
109136 KB |
Output is correct |
26 |
Correct |
140 ms |
119892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
107604 KB |
Output is correct |
2 |
Correct |
101 ms |
107600 KB |
Output is correct |
3 |
Correct |
81 ms |
107600 KB |
Output is correct |
4 |
Correct |
101 ms |
107436 KB |
Output is correct |
5 |
Correct |
75 ms |
107604 KB |
Output is correct |
6 |
Correct |
99 ms |
107452 KB |
Output is correct |
7 |
Correct |
101 ms |
107600 KB |
Output is correct |
8 |
Correct |
78 ms |
107472 KB |
Output is correct |
9 |
Correct |
80 ms |
107860 KB |
Output is correct |
10 |
Correct |
92 ms |
108700 KB |
Output is correct |
11 |
Correct |
88 ms |
108136 KB |
Output is correct |
12 |
Correct |
87 ms |
108724 KB |
Output is correct |
13 |
Correct |
94 ms |
107744 KB |
Output is correct |
14 |
Correct |
93 ms |
108332 KB |
Output is correct |
15 |
Correct |
111 ms |
108484 KB |
Output is correct |
16 |
Correct |
103 ms |
109256 KB |
Output is correct |
17 |
Correct |
245 ms |
140112 KB |
Output is correct |
18 |
Correct |
201 ms |
134224 KB |
Output is correct |
19 |
Correct |
190 ms |
138320 KB |
Output is correct |
20 |
Correct |
184 ms |
131156 KB |
Output is correct |
21 |
Correct |
208 ms |
130388 KB |
Output is correct |
22 |
Correct |
260 ms |
153428 KB |
Output is correct |
23 |
Correct |
150 ms |
123796 KB |
Output is correct |
24 |
Correct |
246 ms |
144496 KB |
Output is correct |
25 |
Correct |
96 ms |
109136 KB |
Output is correct |
26 |
Correct |
140 ms |
119892 KB |
Output is correct |
27 |
Correct |
104 ms |
116052 KB |
Output is correct |
28 |
Correct |
790 ms |
238928 KB |
Output is correct |
29 |
Execution timed out |
1065 ms |
339132 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
323 ms |
214104 KB |
Output is correct |
2 |
Correct |
305 ms |
214100 KB |
Output is correct |
3 |
Correct |
407 ms |
232792 KB |
Output is correct |
4 |
Correct |
334 ms |
237104 KB |
Output is correct |
5 |
Correct |
503 ms |
264972 KB |
Output is correct |
6 |
Correct |
456 ms |
264200 KB |
Output is correct |
7 |
Correct |
520 ms |
264788 KB |
Output is correct |
8 |
Correct |
554 ms |
264840 KB |
Output is correct |
9 |
Correct |
898 ms |
396116 KB |
Output is correct |
10 |
Correct |
393 ms |
205536 KB |
Output is correct |
11 |
Correct |
685 ms |
303520 KB |
Output is correct |
12 |
Correct |
82 ms |
107648 KB |
Output is correct |
13 |
Correct |
78 ms |
107600 KB |
Output is correct |
14 |
Correct |
90 ms |
107536 KB |
Output is correct |
15 |
Correct |
84 ms |
107600 KB |
Output is correct |
16 |
Correct |
97 ms |
107600 KB |
Output is correct |
17 |
Correct |
93 ms |
107464 KB |
Output is correct |
18 |
Correct |
266 ms |
214100 KB |
Output is correct |
19 |
Correct |
279 ms |
214064 KB |
Output is correct |
20 |
Correct |
345 ms |
213896 KB |
Output is correct |
21 |
Correct |
256 ms |
214100 KB |
Output is correct |
22 |
Correct |
871 ms |
393804 KB |
Output is correct |
23 |
Execution timed out |
1048 ms |
404296 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
488 ms |
283172 KB |
Output is correct |
2 |
Correct |
708 ms |
324600 KB |
Output is correct |
3 |
Correct |
257 ms |
214096 KB |
Output is correct |
4 |
Correct |
302 ms |
214096 KB |
Output is correct |
5 |
Execution timed out |
1056 ms |
346576 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |