#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
using vi = vector <int>;
// dp[i][j] = max grams caught if last pier in column <= i-1 and also\
caught the first j catfish from column i
// pier worth extending up to every catfish or until the end (O(n+m) optimal maximal piers)
const ll MAXN = 3E3+16, INF = ll(1E18)+16;
ll dp[MAXN][MAXN];
vii ccs[MAXN];
// vll ps[MAXN];
ll max_weights (int n, int m, vi vx, vi vy, vi vw) {
for (ll i = 0; i < m; i++)
ccs[vx[i]].push_back({ vy[i], vw[i] });
for (ll x = 0; x < n; x++) {
sort(ccs[x].begin(), ccs[x].end());
ccs[x].insert(ccs[x].begin(), ii{ -1, 0 });
// ps[x].push_back(0);
ll acc = 0;
for (auto &[y, w] : ccs[x]) {
acc += w;
w = acc;
}
}
auto fget = [&](ll x, ll y) -> ll { // pier at column x up until y
// ll ans = 0;
if (x < 0 || n <= x) return 0;
return (upper_bound(ccs[x].begin(), ccs[x].end(), ii{ y-1, INF })-1)->second;
// if ()
};
auto ffix = [&](ll x1, ll y1, ll x2, ll y2) -> ll { // fix the combination of those dps
assert(x1 < x2);
if (x1+2 < x2) return 0;
if (x1+2 == x2) {
return fget(x1+1, min(y1, y2));
}
if (x1+1 == x2) {
return fget(x1, y2) + fget(x2, y1);
}
assert(false);
};
ll ans = 0;
for (ll x = 0; x < n; x++) {
for (ll y = 0; y <= n; y++) {
ll ra = fget(x-1, y) + fget(x+1, y);
dp[x][y] = ra;
for (ll x2 = 0; x2 < x; x2++) {
for (ll y2 = 0; y2 <= n; y2++) {
dp[x][y] = max(dp[x][y], dp[x2][y2] + ra - ffix(x2, y2, x, y));
}
}
// if (x == 2) cerr << dp[x][y] << '\n';
ans = max(ans, dp[x][y]);
}
}
return ans;
}
Compilation message
fish.cpp:10:1: warning: multi-line comment [-Wcomment]
10 | // dp[i][j] = max grams caught if last pier in column <= i-1 and also\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1051 ms |
8420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1031 ms |
5720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1031 ms |
5720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1051 ms |
8420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |