#include "fish.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define lb lower_bound
#define ub upper_bound
const int MAX=2e5+10;
vector<pair<ll,ll>> y[MAX];
vector<ll> p[MAX];
vector<vector<ll>> dp[MAX];
vector<ll> can[MAX];
ll getSum(int x,ll l,ll r){
if(l>r)return 0;
int L=lb(all(y[x]),make_pair(l,0ll))-y[x].begin();
int R=ub(all(y[x]),make_pair(r+1,0ll))-y[x].begin()-1;
if(L<=R){
if(L==0)return p[x][R];
return p[x][R]-p[x][L-1];
}
return 0;
}
vector<vector<ll>> sumF[MAX];
vector<vector<ll>> sumB[MAX];
vector<pair<int,int>> vec[MAX];
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W) {
// assert(N<=300);
int MX=0;
bool sub=1;
for(int i=0;i<M;i++){
X[i]++;
Y[i]++;
y[X[i]].pb({Y[i],i});
vec[Y[i]].pb({X[i],W[i]});
sub&=(X[i]%2==1);
MX=max(MX,X[i]);
}
if(sub){
ll ans=0;
for(int i=0;i<M;i++)ans+=W[i];
return ans;
}
if(MX<=2){
if(N==2){
ll f=0,f1=0;
for(int i=0;i<M;i++){
if(X[i]%2)f+=W[i];
else f1+=W[i];
}
return max(f,f1);
}
ll sum=0;
for(int i=0;i<M;i++){
if(X[i]%2==0)sum+=W[i];
}
ll ans=sum;
for(int i=1;i<=N;i++){
for(auto [x,w]:vec[i]){
if(x%2==1)sum+=w;
else sum-=w;
}
ans=max(ans,sum);
}
return ans;
}
for(int i=1;i<=N;i++){
if(y[i].empty())continue;
sort(all(y[i]));
p[i].pb(W[y[i][0].S]);
for(int j=1;j<sz(y[i]);j++){
p[i].pb(p[i].back()+W[y[i][j].S]);
}
}
// cout<<y[5][0].F<<"\n";
can[0].pb(0);
can[N+1].pb(0);
for(int i=1;i<=N;i++){
can[i].pb(0);
if(i>0){
for(auto [x,b]:y[i-1])can[i].pb(x);
}
if(i+1<=N){
for(auto [x,b]:y[i+1])can[i].pb(x);
}
sort(all(can[i]));
can[i].erase(unique(all(can[i])),can[i].end());
}
for(int i=1;i<=N+1;i++){
dp[i].resize(sz(can[i]));
for(int j=0;j<sz(dp[i]);j++){
dp[i][j].resize(sz(can[i-1]));
for(int k=0;k<sz(can[i-1]);k++){
dp[i][j][k]=0;
}
}
}
for(int i=0;i<N;i++){
sumF[i].resize(sz(can[i]));
for(int j=0;j<sz(can[i]);j++){
sumF[i][j].resize(sz(can[i+1]));
for(int k=0;k<sz(can[i+1]);k++){
sumF[i][j][k]=getSum(i+1,can[i+1][k]+1,can[i][j]);
}
}
}
for(int i=1;i<=N+1;i++){
sumB[i].resize(sz(can[i]));
for(int j=0;j<sz(can[i]);j++){
sumB[i][j].resize(sz(can[i-1]));
for(int k=0;k<sz(can[i-1]);k++){
sumB[i][j][k]=getSum(i-1,can[i-1][k]+1,can[i][j]);
}
}
}
for(int i=1;i<=N;i++){
for(int j=0;j<sz(can[i]);j++){
for(int k=0;k<sz(can[i-1]);k++){
for(int f=0;f<sz(can[i+1]);f++){
ll nxt=dp[i][j][k];
{
nxt+=max(sumF[i-1][k][j],sumB[i+1][f][j]);
}
dp[i+1][f][j]=max(dp[i+1][f][j],nxt);
}
}
}
}
ll ans=0;
for(int j=0;j<sz(can[N]);j++)ans=max(ans,dp[N+1][0][j]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
40136 KB |
Output is correct |
2 |
Correct |
43 ms |
41152 KB |
Output is correct |
3 |
Correct |
16 ms |
33112 KB |
Output is correct |
4 |
Correct |
16 ms |
33112 KB |
Output is correct |
5 |
Correct |
104 ms |
53188 KB |
Output is correct |
6 |
Correct |
130 ms |
56180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33112 KB |
Output is correct |
2 |
Correct |
64 ms |
44212 KB |
Output is correct |
3 |
Correct |
69 ms |
47636 KB |
Output is correct |
4 |
Correct |
35 ms |
40648 KB |
Output is correct |
5 |
Correct |
45 ms |
41932 KB |
Output is correct |
6 |
Correct |
16 ms |
33116 KB |
Output is correct |
7 |
Correct |
16 ms |
33308 KB |
Output is correct |
8 |
Correct |
16 ms |
33116 KB |
Output is correct |
9 |
Correct |
16 ms |
33112 KB |
Output is correct |
10 |
Correct |
15 ms |
33116 KB |
Output is correct |
11 |
Correct |
15 ms |
33272 KB |
Output is correct |
12 |
Correct |
36 ms |
40656 KB |
Output is correct |
13 |
Correct |
44 ms |
41920 KB |
Output is correct |
14 |
Correct |
38 ms |
40244 KB |
Output is correct |
15 |
Correct |
40 ms |
39744 KB |
Output is correct |
16 |
Correct |
36 ms |
40252 KB |
Output is correct |
17 |
Correct |
42 ms |
41152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
33112 KB |
Output is correct |
2 |
Correct |
49 ms |
55120 KB |
Output is correct |
3 |
Correct |
80 ms |
70512 KB |
Output is correct |
4 |
Correct |
75 ms |
67020 KB |
Output is correct |
5 |
Correct |
116 ms |
85960 KB |
Output is correct |
6 |
Correct |
119 ms |
85664 KB |
Output is correct |
7 |
Correct |
112 ms |
85960 KB |
Output is correct |
8 |
Correct |
111 ms |
85792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33112 KB |
Output is correct |
2 |
Correct |
15 ms |
33108 KB |
Output is correct |
3 |
Correct |
16 ms |
33112 KB |
Output is correct |
4 |
Correct |
16 ms |
33112 KB |
Output is correct |
5 |
Correct |
15 ms |
33328 KB |
Output is correct |
6 |
Correct |
17 ms |
33116 KB |
Output is correct |
7 |
Correct |
17 ms |
33112 KB |
Output is correct |
8 |
Correct |
17 ms |
33116 KB |
Output is correct |
9 |
Correct |
16 ms |
33372 KB |
Output is correct |
10 |
Correct |
17 ms |
34248 KB |
Output is correct |
11 |
Correct |
16 ms |
33628 KB |
Output is correct |
12 |
Correct |
18 ms |
33884 KB |
Output is correct |
13 |
Correct |
17 ms |
33368 KB |
Output is correct |
14 |
Correct |
17 ms |
33624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33112 KB |
Output is correct |
2 |
Correct |
15 ms |
33108 KB |
Output is correct |
3 |
Correct |
16 ms |
33112 KB |
Output is correct |
4 |
Correct |
16 ms |
33112 KB |
Output is correct |
5 |
Correct |
15 ms |
33328 KB |
Output is correct |
6 |
Correct |
17 ms |
33116 KB |
Output is correct |
7 |
Correct |
17 ms |
33112 KB |
Output is correct |
8 |
Correct |
17 ms |
33116 KB |
Output is correct |
9 |
Correct |
16 ms |
33372 KB |
Output is correct |
10 |
Correct |
17 ms |
34248 KB |
Output is correct |
11 |
Correct |
16 ms |
33628 KB |
Output is correct |
12 |
Correct |
18 ms |
33884 KB |
Output is correct |
13 |
Correct |
17 ms |
33368 KB |
Output is correct |
14 |
Correct |
17 ms |
33624 KB |
Output is correct |
15 |
Correct |
21 ms |
33372 KB |
Output is correct |
16 |
Correct |
43 ms |
38236 KB |
Output is correct |
17 |
Execution timed out |
1031 ms |
415568 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33112 KB |
Output is correct |
2 |
Correct |
15 ms |
33108 KB |
Output is correct |
3 |
Correct |
16 ms |
33112 KB |
Output is correct |
4 |
Correct |
16 ms |
33112 KB |
Output is correct |
5 |
Correct |
15 ms |
33328 KB |
Output is correct |
6 |
Correct |
17 ms |
33116 KB |
Output is correct |
7 |
Correct |
17 ms |
33112 KB |
Output is correct |
8 |
Correct |
17 ms |
33116 KB |
Output is correct |
9 |
Correct |
16 ms |
33372 KB |
Output is correct |
10 |
Correct |
17 ms |
34248 KB |
Output is correct |
11 |
Correct |
16 ms |
33628 KB |
Output is correct |
12 |
Correct |
18 ms |
33884 KB |
Output is correct |
13 |
Correct |
17 ms |
33368 KB |
Output is correct |
14 |
Correct |
17 ms |
33624 KB |
Output is correct |
15 |
Correct |
21 ms |
33372 KB |
Output is correct |
16 |
Correct |
43 ms |
38236 KB |
Output is correct |
17 |
Execution timed out |
1031 ms |
415568 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
33112 KB |
Output is correct |
2 |
Correct |
49 ms |
55120 KB |
Output is correct |
3 |
Correct |
80 ms |
70512 KB |
Output is correct |
4 |
Correct |
75 ms |
67020 KB |
Output is correct |
5 |
Correct |
116 ms |
85960 KB |
Output is correct |
6 |
Correct |
119 ms |
85664 KB |
Output is correct |
7 |
Correct |
112 ms |
85960 KB |
Output is correct |
8 |
Correct |
111 ms |
85792 KB |
Output is correct |
9 |
Correct |
146 ms |
101204 KB |
Output is correct |
10 |
Correct |
101 ms |
70212 KB |
Output is correct |
11 |
Correct |
174 ms |
107060 KB |
Output is correct |
12 |
Correct |
19 ms |
33116 KB |
Output is correct |
13 |
Correct |
19 ms |
33112 KB |
Output is correct |
14 |
Correct |
15 ms |
33116 KB |
Output is correct |
15 |
Correct |
16 ms |
33112 KB |
Output is correct |
16 |
Correct |
16 ms |
33132 KB |
Output is correct |
17 |
Correct |
15 ms |
33116 KB |
Output is correct |
18 |
Correct |
16 ms |
33116 KB |
Output is correct |
19 |
Correct |
19 ms |
33096 KB |
Output is correct |
20 |
Correct |
46 ms |
55124 KB |
Output is correct |
21 |
Correct |
46 ms |
55124 KB |
Output is correct |
22 |
Correct |
175 ms |
104020 KB |
Output is correct |
23 |
Correct |
243 ms |
149560 KB |
Output is correct |
24 |
Correct |
255 ms |
159576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
40136 KB |
Output is correct |
2 |
Correct |
43 ms |
41152 KB |
Output is correct |
3 |
Correct |
16 ms |
33112 KB |
Output is correct |
4 |
Correct |
16 ms |
33112 KB |
Output is correct |
5 |
Correct |
104 ms |
53188 KB |
Output is correct |
6 |
Correct |
130 ms |
56180 KB |
Output is correct |
7 |
Correct |
16 ms |
33112 KB |
Output is correct |
8 |
Correct |
64 ms |
44212 KB |
Output is correct |
9 |
Correct |
69 ms |
47636 KB |
Output is correct |
10 |
Correct |
35 ms |
40648 KB |
Output is correct |
11 |
Correct |
45 ms |
41932 KB |
Output is correct |
12 |
Correct |
16 ms |
33116 KB |
Output is correct |
13 |
Correct |
16 ms |
33308 KB |
Output is correct |
14 |
Correct |
16 ms |
33116 KB |
Output is correct |
15 |
Correct |
16 ms |
33112 KB |
Output is correct |
16 |
Correct |
15 ms |
33116 KB |
Output is correct |
17 |
Correct |
15 ms |
33272 KB |
Output is correct |
18 |
Correct |
36 ms |
40656 KB |
Output is correct |
19 |
Correct |
44 ms |
41920 KB |
Output is correct |
20 |
Correct |
38 ms |
40244 KB |
Output is correct |
21 |
Correct |
40 ms |
39744 KB |
Output is correct |
22 |
Correct |
36 ms |
40252 KB |
Output is correct |
23 |
Correct |
42 ms |
41152 KB |
Output is correct |
24 |
Correct |
15 ms |
33112 KB |
Output is correct |
25 |
Correct |
49 ms |
55120 KB |
Output is correct |
26 |
Correct |
80 ms |
70512 KB |
Output is correct |
27 |
Correct |
75 ms |
67020 KB |
Output is correct |
28 |
Correct |
116 ms |
85960 KB |
Output is correct |
29 |
Correct |
119 ms |
85664 KB |
Output is correct |
30 |
Correct |
112 ms |
85960 KB |
Output is correct |
31 |
Correct |
111 ms |
85792 KB |
Output is correct |
32 |
Correct |
16 ms |
33112 KB |
Output is correct |
33 |
Correct |
15 ms |
33108 KB |
Output is correct |
34 |
Correct |
16 ms |
33112 KB |
Output is correct |
35 |
Correct |
16 ms |
33112 KB |
Output is correct |
36 |
Correct |
15 ms |
33328 KB |
Output is correct |
37 |
Correct |
17 ms |
33116 KB |
Output is correct |
38 |
Correct |
17 ms |
33112 KB |
Output is correct |
39 |
Correct |
17 ms |
33116 KB |
Output is correct |
40 |
Correct |
16 ms |
33372 KB |
Output is correct |
41 |
Correct |
17 ms |
34248 KB |
Output is correct |
42 |
Correct |
16 ms |
33628 KB |
Output is correct |
43 |
Correct |
18 ms |
33884 KB |
Output is correct |
44 |
Correct |
17 ms |
33368 KB |
Output is correct |
45 |
Correct |
17 ms |
33624 KB |
Output is correct |
46 |
Correct |
21 ms |
33372 KB |
Output is correct |
47 |
Correct |
43 ms |
38236 KB |
Output is correct |
48 |
Execution timed out |
1031 ms |
415568 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |