#include "fish.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e18;
int max_weights(signed N, signed M, vector<signed> X, vector<signed> Y,
vector<signed> W) {
vector<vector<pair<int, int>>> onCol(N);
vector<vector<int>> prefSum(N);
for (int i = 0; i < M; ++i)
onCol[X[i]].emplace_back(Y[i] + 1, W[i]);
for (int i = 0; i < N; ++i) {
sort(onCol[i].begin(), onCol[i].end());
prefSum[i].resize(onCol[i].size() + 1);
for (int j = 0; j < (int)onCol[i].size(); ++j)
prefSum[i][j + 1] = prefSum[i][j] + onCol[i][j].second;
}
vector<vector<int>> interesting(N);
for (int i = 0; i < N; ++i) {
interesting[i].push_back(0);
for (auto [y, w] : onCol[i])
interesting[i].push_back(y);
if (i)
for (auto [y, w] : onCol[i - 1])
interesting[i].push_back(y);
if (i + 1 < N)
for (auto [y, w] : onCol[i + 1])
interesting[i].push_back(y);
interesting[i].push_back(N);
sort(interesting[i].begin(), interesting[i].end());
interesting[i].resize(unique(interesting[i].begin(), interesting[i].end()) -
interesting[i].begin());
}
array<vector<pair<int, int>>, 2> oldDp, suffixMax;
for (int i = 0; i < 2; ++i) {
for (int x : interesting[0]) {
oldDp[i].emplace_back(x, 0);
suffixMax[i].emplace_back(x, 0);
}
}
auto eval = [&](int side, int h) {
auto it = upper_bound(oldDp[side].begin(), oldDp[side].end(), pair(h, INF));
assert(it != oldDp[side].begin());
--it;
return it->second;
};
auto getSum = [&](int i, int h1, int h2) -> int {
int lo = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h1, INF)) -
onCol[i].begin();
int up = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h2, INF)) -
onCol[i].begin();
return prefSum[i][up] - prefSum[i][lo];
};
int sol = 0;
for (int i = 1; i < N; ++i) {
int nbInteressants = interesting[i].size();
vector<pair<int, int>> dp0, dp1;
int curOld = 0;
for (int iHauteur = 0; iHauteur < nbInteressants; ++iHauteur) {
int h = interesting[i][iHauteur];
// 1
int v1 = 0;
int v0 = 0;
while (curOld < (int)interesting[i - 1].size() and
interesting[i - 1][curOld] <= h)
++curOld;
assert(curOld);
v0 = suffixMax[1][curOld - 1].second;
for (int jHauteur = 0; jHauteur < (int)interesting[i - 1].size();
++jHauteur) {
int oldH = interesting[i - 1][jHauteur];
if (oldH > h)
v1 = max(v1, getSum(i, h, oldH) + eval(1, oldH));
if (oldH < h)
v0 = max(v0, getSum(i - 1, oldH, h) + eval(0, oldH));
}
v1 = max(v1, v0);
sol = max(sol, v1);
dp0.emplace_back(h, v0);
dp1.emplace_back(h, v1);
// cout << i << ' ' << h << ' ' << v0 << ' ' << v1 << endl;
}
oldDp[0] = move(dp0);
oldDp[1] = move(dp1);
suffixMax[0] = oldDp[0];
suffixMax[1] = oldDp[1];
for (int h = nbInteressants - 2; h >= 0; --h)
for (int side = 0; side < 2; ++side)
suffixMax[side][h].second =
max(suffixMax[side][h].second, suffixMax[side][h + 1].second);
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
25404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
31300 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
13532 KB |
Output is correct |
2 |
Correct |
47 ms |
13600 KB |
Output is correct |
3 |
Correct |
73 ms |
17544 KB |
Output is correct |
4 |
Correct |
65 ms |
17248 KB |
Output is correct |
5 |
Correct |
115 ms |
23768 KB |
Output is correct |
6 |
Correct |
97 ms |
23756 KB |
Output is correct |
7 |
Correct |
113 ms |
23752 KB |
Output is correct |
8 |
Correct |
105 ms |
23880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
512 KB |
Output is correct |
17 |
Execution timed out |
1093 ms |
4080 KB |
Time limit exceeded |
18 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
512 KB |
Output is correct |
17 |
Execution timed out |
1093 ms |
4080 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
13532 KB |
Output is correct |
2 |
Correct |
47 ms |
13600 KB |
Output is correct |
3 |
Correct |
73 ms |
17544 KB |
Output is correct |
4 |
Correct |
65 ms |
17248 KB |
Output is correct |
5 |
Correct |
115 ms |
23768 KB |
Output is correct |
6 |
Correct |
97 ms |
23756 KB |
Output is correct |
7 |
Correct |
113 ms |
23752 KB |
Output is correct |
8 |
Correct |
105 ms |
23880 KB |
Output is correct |
9 |
Correct |
140 ms |
23788 KB |
Output is correct |
10 |
Correct |
75 ms |
14152 KB |
Output is correct |
11 |
Correct |
190 ms |
27984 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
37 ms |
13524 KB |
Output is correct |
19 |
Correct |
37 ms |
13504 KB |
Output is correct |
20 |
Correct |
48 ms |
13516 KB |
Output is correct |
21 |
Correct |
44 ms |
13524 KB |
Output is correct |
22 |
Correct |
166 ms |
22036 KB |
Output is correct |
23 |
Correct |
220 ms |
27836 KB |
Output is correct |
24 |
Correct |
246 ms |
27952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
25404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |