이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long ;
#define sz(x) (int)(x).size()
#define xx first
#define yy second
//dp0[i][j] -> i. oszlopban j-ig elé építve piert max hogyha mindkettő szomszédosnál magasabb
//dp1[i][j] -> i. oszlopban j-ig elé építve piert max hogyha bal oldali számít
//dp2[i][j] -> i. oszlopban j-ig elé építve piert max hogyha jobb oldali számít
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<pair<int,int>>> lst(N+2, vector<pair<int,int>>());
for(int i=0;i<M;++i) {
lst[X[i]].push_back({Y[i], W[i]});
}
for(int i=0;i<=N+1;++i) lst[i].push_back({N+10,0});
for(auto& i:lst) sort(i.begin(), i.end());
//~ for(auto& i:lst)
//~ for(int j=1;j<sz(i);++j) i[j].yy+=i[j-1].yy;
auto get_sum=[&](int x, int l, int r) -> ll {
ll sum=0;
for(int i=0;i<sz(lst[x]);++i) {
if(l<=lst[x][i].xx && lst[x][i].xx<=r) sum+=lst[x][i].yy;
}
//~ cerr<<x<<","<<l<<","<<r<<" -> "<<sum<<"\n";
return sum;
};
vector<ll> dp0(lst[0].size());
vector<ll> dp1(lst[0].size());
vector<ll> dp2(lst[0].size());
for(int i=1;i<N;++i) {
vector<ll> ndp0(lst[i].size());
vector<ll> ndp1(lst[i].size());
vector<ll> ndp2(lst[i].size());
//dp0
for(int j=0;j<sz(lst[i]);++j) {
for(int k=0;k<sz(lst[i-1]);++k) {
ndp0[j]=max({ndp0[j], dp1[k], dp2[k]+get_sum(i-1, lst[i-1][k].xx, lst[i][j].xx-1)});
}
}
//dp1
for(int j=0;j<sz(lst[i]);++j) {
for(int k=0;k<sz(lst[i-1]);++k) {
ndp1[j]=max({ndp1[j], max(dp1[k],dp0[k])+get_sum(i, lst[i][j].xx, lst[i-1][k].xx-1)});
}
}
//dp2
for(int j=0;j<sz(lst[i]);++j) {
for(int k=0;k<sz(lst[i-1]);++k) {
ndp2[j]=max({ndp2[j], dp2[k]+get_sum(i-1, lst[i-1][k].xx, lst[i][j].xx-1), dp0[k]});
}
}
//~ cerr<<i<<", 0: "; for(auto j:ndp0) cerr<<j<<" ";cerr<<"\n";
//~ cerr<<i<<", 1: "; for(auto j:ndp1) cerr<<j<<" ";cerr<<"\n";
//~ cerr<<i<<", 2: "; for(auto j:ndp2) cerr<<j<<" ";cerr<<"\n\n";
dp0.swap(ndp0);
dp1.swap(ndp1);
dp2.swap(ndp2);
}
return max({
*max_element(dp0.begin(), dp0.end()),
*max_element(dp1.begin(), dp1.end()),
*max_element(dp2.begin(), dp2.end())
});
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |