#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);
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 |
Runtime error |
45 ms |
29964 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1091 ms |
48184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
28460 KB |
Output is correct |
2 |
Correct |
46 ms |
28480 KB |
Output is correct |
3 |
Correct |
95 ms |
31280 KB |
Output is correct |
4 |
Correct |
82 ms |
32676 KB |
Output is correct |
5 |
Correct |
150 ms |
38692 KB |
Output is correct |
6 |
Correct |
149 ms |
39040 KB |
Output is correct |
7 |
Correct |
151 ms |
39076 KB |
Output is correct |
8 |
Correct |
150 ms |
39064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
28460 KB |
Output is correct |
2 |
Correct |
46 ms |
28480 KB |
Output is correct |
3 |
Correct |
95 ms |
31280 KB |
Output is correct |
4 |
Correct |
82 ms |
32676 KB |
Output is correct |
5 |
Correct |
150 ms |
38692 KB |
Output is correct |
6 |
Correct |
149 ms |
39040 KB |
Output is correct |
7 |
Correct |
151 ms |
39076 KB |
Output is correct |
8 |
Correct |
150 ms |
39064 KB |
Output is correct |
9 |
Correct |
209 ms |
43736 KB |
Output is correct |
10 |
Incorrect |
150 ms |
24248 KB |
1st lines differ - on the 1st token, expected: '36454348383152', found: '36364983059693' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
45 ms |
29964 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |