#include "fish.h"
#include "bits/stdc++.h"
#include <vector>
struct CaF {
long long x, w;
};
using ll = long long;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
using namespace std;
vector<vector<CaF>> fi(N);
for (int i = 0; i < N; ++i) {
fi[i].push_back({-1, 0});
}
for (int i = 0; i < M; ++i) {
fi[X[i]].push_back({Y[i], W[i]});
}
for (int i = 0; i < N; ++i) {
sort(fi[i].begin(), fi[i].end(), [](const CaF &l, const CaF &r) { return l.x < r.x; });
}
vector<ll> dpU(fi[0].size()), dpD(fi[0].size());
for (int i = 1; i < N; ++i) {
vector<ll> dpNU(fi[i].size()), dpND(fi[i].size()), dp0(fi[i].size());
int laP = 0;
ll su = 0;
ll beSu = 1e9;
int be = 0;
for (int j = 0; j < fi[i].size(); ++j) {
while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
su += fi[i - 1][laP].w;
if (dpU[laP] - su > dpU[be] - beSu) {
be = laP;
beSu = su;
}
laP++;
}
dpNU[j] = dpU[be] + su - beSu;
}
laP = fi[i - 1].size() - 1;
su = 0;
beSu = 0;
be = fi[i - 1].size() - 1;
for (int j = fi[i].size() - 1; j >= 0; --j) {
while (laP >= 0 && fi[i - 1][laP].x > fi[i][j].x) {
laP--;
if (dpD[laP] - su > dpD[be] - beSu) {
be = laP;
beSu = su;
}
}
dpND[j] = max(dpD[be] + su - beSu, dpNU[j]);
su += fi[i][j].w;
}
laP = 0;
su = 0;
for (int j = 0; j < fi[i - 1].size(); ++j) {
while (laP < fi[i].size() && fi[i - 1][j].x >= fi[i][laP].x) {
su += fi[i][laP++].w;
}
dp0[min(laP, (int) fi[i].size() - 1)] = max(dpD[j] + su, dp0[laP - 1]);
}
for (int j = dp0.size() - 1; j >= 0; --j) {
dpNU[j] = max(dp0[j], dpNU[j]);
}
dpD = dpND;
dpU = dpNU;
}
return max(*max_element(dpU.begin(), dpU.end()), *max_element(dpD.begin(), dpD.end()));
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int j = 0; j < fi[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~
fish.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
| ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:33:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
| ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = 0; j < fi[i - 1].size(); ++j) {
| ~~^~~~~~~~~~~~~~~~~~
fish.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | while (laP < fi[i].size() && fi[i - 1][j].x >= fi[i][laP].x) {
| ~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
10944 KB |
Output is correct |
2 |
Correct |
37 ms |
13116 KB |
Output is correct |
3 |
Correct |
15 ms |
5724 KB |
Output is correct |
4 |
Correct |
11 ms |
5724 KB |
Output is correct |
5 |
Correct |
89 ms |
27940 KB |
Output is correct |
6 |
Correct |
91 ms |
28624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
54 ms |
17676 KB |
Output is correct |
3 |
Correct |
63 ms |
20924 KB |
Output is correct |
4 |
Correct |
32 ms |
10948 KB |
Output is correct |
5 |
Correct |
49 ms |
13000 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
11 ms |
5704 KB |
Output is correct |
11 |
Correct |
12 ms |
5724 KB |
Output is correct |
12 |
Correct |
31 ms |
12884 KB |
Output is correct |
13 |
Correct |
38 ms |
15304 KB |
Output is correct |
14 |
Correct |
32 ms |
11504 KB |
Output is correct |
15 |
Correct |
34 ms |
13508 KB |
Output is correct |
16 |
Correct |
32 ms |
11360 KB |
Output is correct |
17 |
Correct |
35 ms |
12732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
5720 KB |
Output is correct |
2 |
Correct |
11 ms |
5724 KB |
Output is correct |
3 |
Incorrect |
38 ms |
8864 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194714671878' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194714671878' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194714671878' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
5720 KB |
Output is correct |
2 |
Correct |
11 ms |
5724 KB |
Output is correct |
3 |
Incorrect |
38 ms |
8864 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
10944 KB |
Output is correct |
2 |
Correct |
37 ms |
13116 KB |
Output is correct |
3 |
Correct |
15 ms |
5724 KB |
Output is correct |
4 |
Correct |
11 ms |
5724 KB |
Output is correct |
5 |
Correct |
89 ms |
27940 KB |
Output is correct |
6 |
Correct |
91 ms |
28624 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
54 ms |
17676 KB |
Output is correct |
9 |
Correct |
63 ms |
20924 KB |
Output is correct |
10 |
Correct |
32 ms |
10948 KB |
Output is correct |
11 |
Correct |
49 ms |
13000 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
11 ms |
5704 KB |
Output is correct |
17 |
Correct |
12 ms |
5724 KB |
Output is correct |
18 |
Correct |
31 ms |
12884 KB |
Output is correct |
19 |
Correct |
38 ms |
15304 KB |
Output is correct |
20 |
Correct |
32 ms |
11504 KB |
Output is correct |
21 |
Correct |
34 ms |
13508 KB |
Output is correct |
22 |
Correct |
32 ms |
11360 KB |
Output is correct |
23 |
Correct |
35 ms |
12732 KB |
Output is correct |
24 |
Correct |
11 ms |
5720 KB |
Output is correct |
25 |
Correct |
11 ms |
5724 KB |
Output is correct |
26 |
Incorrect |
38 ms |
8864 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
27 |
Halted |
0 ms |
0 KB |
- |