#include "fish.h"
#include <bits/stdc++.h>
#define MX mx[i][idx][b]
#define int long long
using namespace std;
const int INF=1e18;
vector <int> v[100001];
vector <pair <int, int>> s[100001],mx[100002][4][2];
int n,m;
int x,y,res;
void update(int pos, int val, int i, int idx){
mx[pos][idx][0].push_back({i,val});
mx[pos][idx][1].push_back({n-i+1,val});
}
int get(int pos, int i, int idx, int b){
if (b)
pos=n-pos+1;
int p=upper_bound(MX.begin(),MX.end(),make_pair(pos,INF))-MX.begin()-1;
return (p<0?-INF:MX[p].second);
}
int sum(int i, int j){
if (i<0)
return 0;
return s[i][upper_bound(s[i].begin(),s[i].end(),make_pair(j,INF))-s[i].begin()-1].second;
}
int max_weights(int32_t N, int32_t M, vector <int32_t> X, vector <int32_t> Y, vector <int32_t> W){
n=N;
for (int i=0;i<M;i++){
s[X[i]].push_back({Y[i],W[i]});
if (X[i])
v[X[i]-1].push_back(Y[i]);
if (X[i]<N-1)
v[X[i]+1].push_back(Y[i]);
}
for (int i=0;i<n;i++){
v[i].push_back(-1);
sort(v[i].begin(),v[i].end());
v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
s[i].push_back({-1,0});
sort(s[i].begin(),s[i].end());
for (int j=1;j<s[i].size();j++)
s[i][j].second+=s[i][j-1].second;
}
for (int i:v[n-1]){
update(n,0,i,0);
update(n,0,i,1);
update(n,-sum(n-1,i),i,2);
update(n,sum(n-2,i),i,3);
}
for (int i=n-1;i;i--){
for (int j:v[i-1]){
x=max(max(get(j-1,i+1,2,0)+sum(i,j),get(j-1,i+1,1,0)),max(get(j,i+1,0,1),get(j,i+1,1,1)));
y=max(max(get(j-1,i+1,2,0)+sum(i,j),get(j-1,i+1,1,0)),get(j,i+1,3,1)-sum(i-1,j));
update(i,x,i,0);
update(i,y,i,1);
update(i,x-sum(i-1,j),i,2);
update(i,max(x,y)+sum(i-2,j),i,3);
}
for (int j=0;j<4;j++){
reverse(mx[i][j][1].begin(),mx[i][j][1].end());
for (int k=0;k<2;k++)
for (int l=1;l<mx[i][j][k].size();l++)
mx[i][j][k][l].second=max(mx[i][j][k][l].second,mx[i][j][k][l-1].second);
}
}
return max(get(0,1,0,1),get(0,1,1,1));
}
Compilation message
fish.cpp: In function 'long long int max_weights(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j=1;j<s[i].size();j++)
| ~^~~~~~~~~~~~
fish.cpp:62:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int l=1;l<mx[i][j][k].size();l++)
| ~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
71104 KB |
Output is correct |
2 |
Correct |
129 ms |
76008 KB |
Output is correct |
3 |
Correct |
62 ms |
55188 KB |
Output is correct |
4 |
Correct |
58 ms |
55128 KB |
Output is correct |
5 |
Correct |
372 ms |
159472 KB |
Output is correct |
6 |
Correct |
447 ms |
180844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
23896 KB |
Output is correct |
2 |
Incorrect |
229 ms |
101168 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '40479737800179' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
55120 KB |
Output is correct |
2 |
Correct |
58 ms |
55196 KB |
Output is correct |
3 |
Incorrect |
108 ms |
62288 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
23896 KB |
Output is correct |
2 |
Correct |
5 ms |
23896 KB |
Output is correct |
3 |
Correct |
5 ms |
23896 KB |
Output is correct |
4 |
Correct |
5 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23896 KB |
Output is correct |
6 |
Correct |
5 ms |
23896 KB |
Output is correct |
7 |
Correct |
5 ms |
23896 KB |
Output is correct |
8 |
Incorrect |
5 ms |
23896 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
23896 KB |
Output is correct |
2 |
Correct |
5 ms |
23896 KB |
Output is correct |
3 |
Correct |
5 ms |
23896 KB |
Output is correct |
4 |
Correct |
5 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23896 KB |
Output is correct |
6 |
Correct |
5 ms |
23896 KB |
Output is correct |
7 |
Correct |
5 ms |
23896 KB |
Output is correct |
8 |
Incorrect |
5 ms |
23896 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
23896 KB |
Output is correct |
2 |
Correct |
5 ms |
23896 KB |
Output is correct |
3 |
Correct |
5 ms |
23896 KB |
Output is correct |
4 |
Correct |
5 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23896 KB |
Output is correct |
6 |
Correct |
5 ms |
23896 KB |
Output is correct |
7 |
Correct |
5 ms |
23896 KB |
Output is correct |
8 |
Incorrect |
5 ms |
23896 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
55120 KB |
Output is correct |
2 |
Correct |
58 ms |
55196 KB |
Output is correct |
3 |
Incorrect |
108 ms |
62288 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
71104 KB |
Output is correct |
2 |
Correct |
129 ms |
76008 KB |
Output is correct |
3 |
Correct |
62 ms |
55188 KB |
Output is correct |
4 |
Correct |
58 ms |
55128 KB |
Output is correct |
5 |
Correct |
372 ms |
159472 KB |
Output is correct |
6 |
Correct |
447 ms |
180844 KB |
Output is correct |
7 |
Correct |
5 ms |
23896 KB |
Output is correct |
8 |
Incorrect |
229 ms |
101168 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '40479737800179' |
9 |
Halted |
0 ms |
0 KB |
- |