이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
using i64 = long long;
i64 max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
std::vector<std::vector<int>> pos(N);
for (int i = 0; i < M; ++i) {
pos[X[i]].push_back(i);
}
for (int i = 0; i < N; ++i) {
std::sort(pos[i].begin(), pos[i].end(), [&](int lhs, int rhs) {
return Y[lhs] < Y[rhs];
});
}
auto chmax = [](i64 &x, i64 y) {
x = std::max(x, y);
};
i64 ans = 0;
std::vector<i64> f(M), g(M), max_f(N), max_g(N);
for (int i = 0; i < N; ++i) {
if (i > 0) {
max_f[i] = max_g[i] = std::max(max_f[i - 1], max_g[i - 1]);
}
int len = pos[i].size(), len_1 = i > 0 ? pos[i - 1].size() : 0, p = 0;
i64 val;
if (i < N - 1) {
val = i > 0 ? max_g[i - 1] : 0;
if (i > 1) {
chmax(val, max_f[i - 2]);
}
for (int j = 0; j < len; ++j) {
if (j > 0) {
f[pos[i][j]] = f[pos[i][j - 1]] + W[pos[i][j]];
}
for (; p < len_1 && Y[pos[i - 1][p]] < Y[pos[i][j]]; ++p) {
chmax(val, f[pos[i - 1][p]]);
}
chmax(f[pos[i][j]], val + W[pos[i][j]]);
chmax(max_f[i], f[pos[i][j]]);
chmax(ans, f[pos[i][j]]);
}
}
if (i > 0) {
p = len_1 - 1, val = i > 1 ? max_f[i - 2] : 0;
for (int j = len - 1; j >= 0; --j) {
if (j < len - 1) {
g[pos[i][j]] = g[pos[i][j + 1]] + W[pos[i][j]];
}
for (; p >= 0 && Y[pos[i - 1][p]] > Y[pos[i][j]]; --p) {
chmax(val, g[pos[i - 1][p]]);
}
chmax(g[pos[i][j]], val + W[pos[i][j]]);
chmax(max_g[i], g[pos[i][j]]);
chmax(ans, g[pos[i][j]]);
}
}
}
return ans;
}
# | 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... |