#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 = 1E5+16, INF = ll(1E18)+16;
ll dp[MAXN][2];
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 <= 1; y++) {
ll ra = fget(x-1, y) + fget(x+1, y);
dp[x][y] = ra;
for (ll x2 = max(0LL, x-3); x2 < x; x2++) {
for (ll y2 = 0; y2 <= 1; y2++) {
dp[x][y] = max(dp[x][y], dp[x2][y2] + ra - ffix(x2, y2, x, y));
}
}
// cerr << dp[x][y] << ' ';
ans = max(ans, dp[x][y]);
}
// cerr << '\n';
}
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 |
Incorrect |
30 ms |
9916 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '223762357' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
7260 KB |
Output is correct |
2 |
Correct |
13 ms |
7252 KB |
Output is correct |
3 |
Correct |
23 ms |
9296 KB |
Output is correct |
4 |
Correct |
24 ms |
9484 KB |
Output is correct |
5 |
Correct |
43 ms |
13912 KB |
Output is correct |
6 |
Correct |
40 ms |
13136 KB |
Output is correct |
7 |
Correct |
51 ms |
13648 KB |
Output is correct |
8 |
Correct |
47 ms |
13652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
7260 KB |
Output is correct |
2 |
Correct |
13 ms |
7252 KB |
Output is correct |
3 |
Correct |
23 ms |
9296 KB |
Output is correct |
4 |
Correct |
24 ms |
9484 KB |
Output is correct |
5 |
Correct |
43 ms |
13912 KB |
Output is correct |
6 |
Correct |
40 ms |
13136 KB |
Output is correct |
7 |
Correct |
51 ms |
13648 KB |
Output is correct |
8 |
Correct |
47 ms |
13652 KB |
Output is correct |
9 |
Incorrect |
43 ms |
13652 KB |
1st lines differ - on the 1st token, expected: '99999', found: '1' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
9916 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '223762357' |
2 |
Halted |
0 ms |
0 KB |
- |