#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<ll> dp[MAX][2];
vector<ll> can[MAX];
ll getR(int x,ll r){
if(r<0)return 0;
int R=ub(all(y[x]),make_pair(r+1,-1ll))-y[x].begin()-1;
if(R<0)return 0;
return p[x][R];
}
vector<ll> pref[MAX][2],suf[MAX][2];
vector<pair<int,int>> vec[MAX];
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W) {
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]});
}
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]);
}
}
can[0].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=0;i<=N+1;i++){
dp[i][0].resize(sz(can[i]));
dp[i][1].resize(sz(can[i]));
for(int j=0;j<sz(can[i]);j++){
dp[i][0][j]=dp[i][1][j]=0;
}
}
for(int i=1;i<=N;i++){
{
int r=sz(can[i-1]);
ll mx=0;
for(int j=sz(can[i])-1;j>=0;j--){
while(r-1>=0&&can[i-1][r-1]>=can[i][j]){
mx=max(mx,max(dp[i-1][0][r-1],dp[i-1][1][r-1])+getR(i,can[i-1][r-1]));
r--;
}
dp[i][0][j]=mx+getR(i,can[i][j]);
}
}
{
int r=0;
ll mx=0;
for(int j=0;j<sz(can[i]);j++){
while(r<sz(can[i-1])&&can[i-1][r]<=can[i][j]){
mx=max(mx,dp[i-1][r][1]-getR(i-1,can[i-1][r]));
r++;
}
dp[i][1][j]=mx+getR(i-1,can[i][j]);
dp[i][1][j]=max(dp[i][1][j],dp[i-1][0][0]);
}
}
}
ll ans=0;
for(int j=0;j<sz(can[N]);j++)ans=max(ans,max(dp[N][0][j],dp[N][1][j]));
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
65728 KB |
Output is correct |
2 |
Correct |
81 ms |
68504 KB |
Output is correct |
3 |
Correct |
35 ms |
56656 KB |
Output is correct |
4 |
Correct |
35 ms |
56664 KB |
Output is correct |
5 |
Incorrect |
191 ms |
96036 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '149814466847975' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
47196 KB |
1st lines differ - on the 1st token, expected: '2', found: '3' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
56664 KB |
Output is correct |
2 |
Correct |
35 ms |
56664 KB |
Output is correct |
3 |
Incorrect |
56 ms |
62408 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '58750855824894' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
47192 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
47192 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
47192 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
56664 KB |
Output is correct |
2 |
Correct |
35 ms |
56664 KB |
Output is correct |
3 |
Incorrect |
56 ms |
62408 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '58750855824894' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
65728 KB |
Output is correct |
2 |
Correct |
81 ms |
68504 KB |
Output is correct |
3 |
Correct |
35 ms |
56656 KB |
Output is correct |
4 |
Correct |
35 ms |
56664 KB |
Output is correct |
5 |
Incorrect |
191 ms |
96036 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '149814466847975' |
6 |
Halted |
0 ms |
0 KB |
- |