이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
long long max_weights(int n, int m, vector<int> x, vector<int> y,
vector<int> w) {
vector<vector<pair<int,int>>> g(n + 2, vector<pair<int,int>>(1, {0,0}));
vector<vector<int>> pts(n + 1, vector<int>(1, 0));
for(int i = 0; i < m; i++){
g[x[i] + 1].emplace_back(y[i] + 1, w[i]);
pts[x[i]].push_back(y[i] + 1);
if(x[i] + 2 <= n) pts[x[i] + 2].push_back(y[i] + 1);
}
for(int i = 1; i <= n; i++){
sort(g[i].begin(), g[i].end());
sort(pts[i].begin(), pts[i].end());
pts[i].resize(unique(pts[i].begin(), pts[i].end()) - pts[i].begin());
}
vector<vector<ll>> sums(n + 2);
for(int i = 0; i <= n + 1; i++){
for(auto [j, x]: g[i]){
sums[i].push_back(x + (sums[i].empty() ? 0 : sums[i].back()));
}
}
vector<vector<ll>> dpl(n + 1);
vector<vector<ll>> dpr(n + 1);
vector<vector<ll>> ans(n + 1);
dpl[0].push_back(0);
dpr[0].push_back(0);
ll fans = 0;
for(int col = 1; col <= n; col++){
for(int row: pts[col]){
ll ans = 0;
auto it = prev(upper_bound(g[col].begin(), g[col].end(), make_pair(row, INF)));
ll sumUp = sums[col].back() - sums[col][it - g[col].begin()];
it = prev(upper_bound(g[col - 1].begin(), g[col - 1].end(), make_pair(row, INF)));
ll removeLeft = sums[col - 1].back() - sums[col - 1][it - g[col - 1].begin()];
auto it2 = prev(upper_bound(pts[col - 1].begin(), pts[col - 1].end(), row));
// left to left
if(row == 0){
dpl[col].push_back(dpl[col - 1][it2 - pts[col - 1].begin()] + sumUp - removeLeft);
}else{
dpl[col].push_back(max(dpl[col].back(), dpl[col - 1][it2 - pts[col - 1].begin()] + sumUp - removeLeft));
}
// left to right
it = prev(upper_bound(g[col + 1].begin(), g[col + 1].end(), make_pair(row, INF)));
dpr[col].push_back(dpl[col - 1][it2 - pts[col - 1].begin()] - removeLeft + sums[col + 1][it - g[col + 1].begin()]);
// right to right
fans = max(ans, dpr[col].back());
//cout << "DP FOR " << col << " " << row << " " << dpr[col].back() << endl;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:8: warning: variable 'fans' set but not used [-Wunused-but-set-variable]
32 | ll fans = 0;
| ^~~~
# | 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... |