#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 302020
typedef long long ll;
typedef pair<int, int> pii;
ll tdp[MAX]; // full dp
ll bdp[MAX]; // zero dp
vector<pii> locs[MAX];
struct bit {
int N;
bool rev;
vector<ll> tree;
bit(int N, bool rev) :N(N + 2), rev(rev) { tree = vector<ll>(N + 3, -1e18); }
void upd(int i, ll v) {
if (!(0 <= i && i < N)) return;
if (rev) i = N - i - 1;
i++;
while (i <= N) {
tree[i] = max(tree[i], v);
i += i & -i;
}
}
ll get(int i) {
if (!(0 <= i && i < N)) return -1e18;
if (rev) i = N - i - 1;
i++;
ll ans = -1e18;
while (i) {
ans = max(ans, tree[i]);
i -= i & -i;
}
return ans;
}
};
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
int i;
for (auto& v : X) v++;
for (auto& v : Y) v++;
for (i = 0; i < M; i++) locs[X[i]].emplace_back(Y[i], W[i]);
for (i = 0; i < N; i++) if (locs[i].size()) sort(locs[i].begin(), locs[i].end());
bit fenu(N + 1, false), fend(N + 1, true);
for (i = 1; i <= N; i++) {
if (i > 2) fend.upd(N + 1, tdp[i - 2]);
if (i > 1) fenu.upd(0, bdp[i - 1]);
for (auto& [y, w] : locs[i]) fenu.upd(y, fenu.get(y - 1) + w);
tdp[i] = fenu.get(N);
for (int j = locs[i].size() - 1; j >= 0; j--) {
ll y = locs[i][j].first;
ll w = locs[i][j].second;
fend.upd(y, fend.get(y + 1) + w);
}
bdp[i] = fend.get(1);
ll sum = 0;
for (auto& v : locs[i]) sum += v.second;
tdp[i] = max(tdp[i], sum + tdp[i - 2]);
}
return fend.get(1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
14144 KB |
Output is correct |
2 |
Correct |
54 ms |
15472 KB |
Output is correct |
3 |
Correct |
15 ms |
10452 KB |
Output is correct |
4 |
Correct |
14 ms |
10452 KB |
Output is correct |
5 |
Correct |
135 ms |
26480 KB |
Output is correct |
6 |
Correct |
152 ms |
28560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
10504 KB |
Output is correct |
2 |
Correct |
14 ms |
10528 KB |
Output is correct |
3 |
Correct |
41 ms |
14028 KB |
Output is correct |
4 |
Correct |
29 ms |
13072 KB |
Output is correct |
5 |
Correct |
57 ms |
17632 KB |
Output is correct |
6 |
Correct |
56 ms |
16972 KB |
Output is correct |
7 |
Correct |
58 ms |
17556 KB |
Output is correct |
8 |
Correct |
56 ms |
17520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
10504 KB |
Output is correct |
2 |
Correct |
14 ms |
10528 KB |
Output is correct |
3 |
Correct |
41 ms |
14028 KB |
Output is correct |
4 |
Correct |
29 ms |
13072 KB |
Output is correct |
5 |
Correct |
57 ms |
17632 KB |
Output is correct |
6 |
Correct |
56 ms |
16972 KB |
Output is correct |
7 |
Correct |
58 ms |
17556 KB |
Output is correct |
8 |
Correct |
56 ms |
17520 KB |
Output is correct |
9 |
Incorrect |
60 ms |
17320 KB |
1st lines differ - on the 1st token, expected: '99999', found: '99997' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
14144 KB |
Output is correct |
2 |
Correct |
54 ms |
15472 KB |
Output is correct |
3 |
Correct |
15 ms |
10452 KB |
Output is correct |
4 |
Correct |
14 ms |
10452 KB |
Output is correct |
5 |
Correct |
135 ms |
26480 KB |
Output is correct |
6 |
Correct |
152 ms |
28560 KB |
Output is correct |
7 |
Incorrect |
4 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |