제출 #1033045

#제출 시각아이디문제언어결과실행 시간메모리
1033045vjudge1메기 농장 (IOI22_fish)C++17
100 / 100
270 ms95608 KiB
#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=3e5+10; vector<pair<ll,ll>> y[MAX]; vector<pair<int,int>> vec[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]; } 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][1][r]-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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...