#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) {
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);
for (int iter = 0; iter < fish_dim; iter++) {
int x = XX[iter], y = YY[iter] + 1, w = WW[iter];
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++) {
/// dp[i][j] = ?
dp[i][j] = max(dp[i][j], ze[i - 1] + );
for (int j2 = 0; j2 < (int) interesting[i - 1].size(); j2++) {
ll cur = dp[i - 1][j2] - get(i, interesting[i][j]);
if (i + 1 < n) {
cur += get(i + 1, interesting[i][j]);
}
dp[i][j] = max(dp[i][j], cur);
}
}**/
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 - 2, interesting[i][j]));
} 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]);
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));
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 |
Runtime error |
127 ms |
69584 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1067 ms |
48928 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
28460 KB |
Output is correct |
2 |
Correct |
48 ms |
28392 KB |
Output is correct |
3 |
Incorrect |
114 ms |
31608 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '30402474740547' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '8866', found: '16621' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '8866', found: '16621' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '8866', found: '16621' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
28460 KB |
Output is correct |
2 |
Correct |
48 ms |
28392 KB |
Output is correct |
3 |
Incorrect |
114 ms |
31608 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '30402474740547' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
69584 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |