#include "fish.h"
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
vvii fishes;
int weightSum(int x, int y1, int y2) {
if (x >= fishes.size() || y2 <= y1)
return 0;
int res = 0;
for (auto [y, w] : fishes[x]) {
if (y1 <= y && y < y2)
res += w;
}
return res;
}
long long max_weights(signed N, signed M, vector<signed> X, std::vector<signed> Y, std::vector<signed> W) {
fishes = vvii(N);
loop(i, M) {
fishes[X[i]].push_back({Y[i], W[i]});
}
fishes.push_back({});
loop(x, N) {
sort(all(fishes[x]));
}
vector<map<int, int>> beforeDp(N);
vector<map<int, int>> bothDp(N);
//bestBefore, bestBeforeAndAfter
loop(x, N) {
if (x == 0) {
for (auto [y, w] : fishes[x + 1]) {
bothDp[0][y + 1] = weightSum(x + 1, 0, y + 1);
}
beforeDp[0][0] = 0;
continue;
}
set<int> heights;
for (auto [y, w] : fishes[x - 1]) {
heights.insert(y + 1);
}
for (auto [y, w] : fishes[x + 1]) {
heights.insert(y + 1);
}
heights.insert(0);
int bestBefore2 = 0;
int bestBoth3 = 0;
if (x >= 2) {
for (auto [prevY, prevScore] : beforeDp[x - 2])
bestBefore2 = max(bestBefore2, prevScore);
}
if (x >= 3) {
for (auto [prevY, prevScore] : bothDp[x - 3])
bestBoth3 = max(bestBoth3, prevScore);
}
for (int height : heights) {
int& both = bothDp[x][height];
int& before = beforeDp[x][height];
int nextWeight = weightSum(x + 1, 0, height);
for (auto [prevHeight, prevScore] : beforeDp[x - 1]) {
int prevCur = weightSum(x - 1, prevHeight, height);
both = max(both, prevScore + prevCur + nextWeight);
before = max(before, prevScore + prevCur);
}
// for (auto [prevY, prevScore] : bothDp[x - 1]) {
// int prevCur = weightSum(x - 1, prevY, height) - weightSum(x, 0, min(prevY, height));
// both = max(both, prevScore + prevCur + nextWeight);
// before = max(before, prevScore + prevCur);
// }
both = max(both, bestBefore2 + weightSum(x - 1, 0, height) + nextWeight);
both = max(both, bestBoth3 + weightSum(x - 1, 0, height) + nextWeight);
before = max(before, bestBefore2 + weightSum(x - 1, 0, height));
before = max(before, bestBoth3 + weightSum(x - 1, 0, height));
}
}
int res = 0;
loop(x, N) {
for (auto [y, score] : beforeDp[x]) {
res = max(res, score);
}
for (auto [y, score] : bothDp[x]) {
res = max(res, score);
}
}
return res;
}
Compilation message
fish.cpp: In function 'long long int weightSum(long long int, long long int, long long int)':
fish.cpp:35:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (x >= fishes.size() || y2 <= y1)
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
19840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
21396 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
24624 KB |
Output is correct |
2 |
Correct |
21 ms |
25984 KB |
Output is correct |
3 |
Correct |
45 ms |
34940 KB |
Output is correct |
4 |
Correct |
40 ms |
33832 KB |
Output is correct |
5 |
Correct |
80 ms |
45220 KB |
Output is correct |
6 |
Correct |
66 ms |
45100 KB |
Output is correct |
7 |
Correct |
69 ms |
45764 KB |
Output is correct |
8 |
Correct |
72 ms |
45956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
24624 KB |
Output is correct |
2 |
Correct |
21 ms |
25984 KB |
Output is correct |
3 |
Correct |
45 ms |
34940 KB |
Output is correct |
4 |
Correct |
40 ms |
33832 KB |
Output is correct |
5 |
Correct |
80 ms |
45220 KB |
Output is correct |
6 |
Correct |
66 ms |
45100 KB |
Output is correct |
7 |
Correct |
69 ms |
45764 KB |
Output is correct |
8 |
Correct |
72 ms |
45956 KB |
Output is correct |
9 |
Correct |
85 ms |
57128 KB |
Output is correct |
10 |
Incorrect |
56 ms |
31680 KB |
1st lines differ - on the 1st token, expected: '36454348383152', found: '36364983059693' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
19840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |