#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
ll max_weights(int n, int m, std::vector<int> XX, std::vector<int> YY, std::vector<int> WW) {
m++;
vector<set<int>> s_interesting(n);
vector<vector<int>> interesting(n);
vector<vector<vector<ll>>> dp(2, vector<vector<ll>> (n));
vector<vector<pair<int, ll>>> fish(n);
int fish_dim = (int) XX.size();
assert((int) XX.size() == fish_dim);
assert((int) YY.size() == fish_dim);
assert((int) WW.size() == fish_dim);
exit(0);
for (int iter = 0; iter < fish_dim; iter++) {
int x = XX[iter], y = YY[iter] + 1, w = WW[iter];
assert(y <= m);
fish[x].push_back({y, w});
vector<int> tr = {x - 1, x + 1};
for (auto &i : tr) {
if (0 <= i && i < n) {
s_interesting[i].insert(y);
}
}
}
for (int i = 0; i < n; i++) {
s_interesting[i].insert(0);
for (auto &j : s_interesting[i]) {
interesting[i].push_back(j);
}
assert(!interesting[i].empty());
dp[0][i].resize((int) interesting[i].size(), 0LL);
dp[1][i].resize((int) interesting[i].size(), 0LL);
sort(fish[i].begin(), fish[i].end());
ll sum = 0;
for (auto &it : fish[i]) {
sum += it.second;
it.second = sum;
}
}
function<ll(int, int)> get = [&] (int x, int y) {
assert(0 <= x && x < n);
assert(0 <= y && y <= m);
int smaller = 0;
int low = 0, high = (int) fish[x].size() - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (fish[x][mid].first <= y) {
smaller = mid + 1;
low = mid + 1;
} else {
high = mid - 1;
}
}
if (smaller == 0) {
return 0LL;
} else {
assert(0 <= smaller - 1 && smaller - 1 < (int) fish[x].size());
return fish[x][smaller - 1].second;
}
};
for (int j = 0; j < (int) interesting[0].size(); j++) {
dp[1][0][j] = get(1, interesting[0][j]);
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < (int) interesting[i].size(); j++) {
ll last_zero = 0;
if (i == 1) {
last_zero = max(last_zero, ((i + 1 < n) ? (get(i + 1, interesting[i][j])) : (0)) + get(0, interesting[i][j]));
} else {
assert(i - 2 >= 0);
for (int j2 = 0; j2 < (int) interesting[i - 2].size(); j2++) {
if (interesting[i - 2][j2] <= interesting[i][j]) {
last_zero = max(last_zero, max(dp[0][i - 2][j2], dp[1][i - 2][j2]) + ((i + 1 < n) ? (get(i + 1, interesting[i][j])) : (0)) + get(i - 1, interesting[i][j]) - get(i - 1, interesting[i - 2][j2]));
} else {
last_zero = max(last_zero, max(dp[0][i - 2][j2], dp[1][i - 2][j2]) + ((i + 1 < n) ? (get(i + 1, interesting[i][j])) : (0)));
}
}
}
dp[0][i][j] = max(dp[0][i][j], last_zero);
dp[1][i][j] = max(dp[1][i][j], last_zero);
{
/// dp[1][i][j]
for (int j2 = 0; j2 < (int) interesting[i - 1].size(); j2++) {
if (interesting[i - 1][j2] <= interesting[i][j]) {
/// dp[1][i - 1][j2]
{
ll cur = dp[1][i - 1][j2] + ((i + 1 < n) ? (get(i + 1, interesting[i][j])) : (0)) + get(i - 1, interesting[i][j]) - get(i - 1, interesting[i - 1][j2]) - (get(i, interesting[i - 1][j2]));
dp[1][i][j] = max(dp[1][i][j], cur);
}
}
}
}
{
/// dp[0][i][j]
for (int j2 = 0; j2 < (int) interesting[i - 1].size(); j2++) {
if (interesting[i - 1][j2] <= interesting[i][j]) {
/// dp[0][i - 1][j2] and dp[1][i - 1][j2]
{
ll cur = max(dp[0][i - 1][j2], dp[1][i - 1][j2]) + ((i + 1 < n) ? (get(i + 1, interesting[i][j])) : (0)) - (get(i, interesting[i][j]));
dp[0][i][j] = max(dp[0][i][j], cur);
}
}
}
}
}
}
ll sol = 0;
for (auto &mtr : dp) {
for (auto &v : mtr) {
for (auto &x : v) {
sol = max(sol, x);
}
}
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
14888 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14368 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14368 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
14888 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |