#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 3e5 + 10;
int n, m, x[maxn], y[maxn], w[maxn];
vector<int> num[maxn];
vector<int> val[maxn];
vector<ll> dp1[maxn], dp2[maxn], sum[maxn];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N, m = M;
for (int i = 0; i < m; i++){
x[i] = X[i];
y[i] = Y[i];
w[i] = W[i];
num[x[i]].push_back(y[i]-1);
num[x[i]].push_back(y[i]);
}
// debug(0);
for (int i = 0; i < n; i++){
num[i].push_back(-1);
num[i].push_back(n-1);
sort(all(num[i]));
num[i].resize(distance(num[i].begin(), unique(all(num[i]))));
for (auto x: num[i]){
val[i].push_back(0);
}
}
for (int i = 0; i < m; i++){
int idx = lower_bound(all(num[x[i]]), y[i]) - num[x[i]].begin();
val[x[i]][idx] = w[i];
}
// debug(1);
dp1[0].resize(val[0].size(), 0);
dp2[0].resize(val[0].size(), 0);
sum[0].resize(val[0].size(), 0);
for (int i = 1; i < val[0].size(); i++){
dp1[0][i] = dp1[0][i-1] + val[0][i];
sum[0][i] = sum[0][i-1] + val[0][i];
}
// for (int i = 0; i < val[0].size(); i++) debug(0, i, num[0][i], dp1[0][i], dp2[0][i], sum[0][i]);
for (int i = 1; i < n; i++){
dp1[i].resize(val[i].size());
dp2[i].resize(val[i].size());
sum[i].resize(val[i].size());
for (int j = 0; j < val[i].size(); j++){
int idx = upper_bound(all(num[i-1]), num[i][j]) - num[i-1].begin() - 1;
dp1[i][j] = dp1[i-1][idx];
if (j){
dp1[i][j] = max(dp1[i][j], dp1[i][j-1] + val[i][j]);
}
if (i > 1){
dp1[i][j] = max(dp1[i][j], dp2[i-1][0]);
dp1[i][j] = max(dp1[i][j], dp2[i-2][0] + sum[i-1][idx]);
}
}
for (int j = val[i].size()-1; ~j; j--){
// debug(i, j);
int idx = lower_bound(all(num[i-1]), num[i][j]) - num[i-1].begin();
dp2[i][j] = dp2[i-1][idx];
if (j + 1 != val[i].size()) dp2[i][j] = max(dp2[i][j], dp2[i][j+1] + val[i][j+1]);
if (i > 1){
// debug(1, dp1[i-2][val[i-2].size()-1]);
dp2[i][j] = max(dp2[i][j], dp1[i-2][val[i-2].size()-1]);
}
}
for (int j = 1; j < val[i].size(); j++){
sum[i][j] = sum[i][j-1] + val[i][j];
}
//for (int j = 0; j < val[i].size(); j++) debug(i, j, num[i][j], dp1[i][j], dp2[i][j], sum[i][j]);
}
ll ans = max(dp2[n-1][0], dp1[n-2][val[n-2].size()-1]);
return ans;
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:45:13: warning: unused variable 'x' [-Wunused-variable]
45 | for (auto x: num[i]){
| ^
fish.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 1; i < val[0].size(); i++){
| ~~^~~~~~~~~~~~~~~
fish.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int j = 0; j < val[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
fish.cpp:81:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | if (j + 1 != val[i].size()) dp2[i][j] = max(dp2[i][j], dp2[i][j+1] + val[i][j+1]);
| ~~~~~~^~~~~~~~~~~~~~~~
fish.cpp:87:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int j = 1; j < val[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
55640 KB |
Output is correct |
2 |
Correct |
97 ms |
58344 KB |
Output is correct |
3 |
Correct |
47 ms |
51108 KB |
Output is correct |
4 |
Correct |
46 ms |
51140 KB |
Output is correct |
5 |
Correct |
211 ms |
73344 KB |
Output is correct |
6 |
Correct |
234 ms |
81964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
35548 KB |
Output is correct |
2 |
Correct |
134 ms |
61580 KB |
Output is correct |
3 |
Correct |
158 ms |
68884 KB |
Output is correct |
4 |
Correct |
84 ms |
56896 KB |
Output is correct |
5 |
Correct |
96 ms |
59908 KB |
Output is correct |
6 |
Correct |
21 ms |
35484 KB |
Output is correct |
7 |
Correct |
17 ms |
35540 KB |
Output is correct |
8 |
Correct |
18 ms |
35528 KB |
Output is correct |
9 |
Correct |
17 ms |
35536 KB |
Output is correct |
10 |
Correct |
47 ms |
51160 KB |
Output is correct |
11 |
Correct |
46 ms |
51120 KB |
Output is correct |
12 |
Correct |
84 ms |
56980 KB |
Output is correct |
13 |
Correct |
100 ms |
59988 KB |
Output is correct |
14 |
Correct |
90 ms |
56992 KB |
Output is correct |
15 |
Correct |
115 ms |
59392 KB |
Output is correct |
16 |
Correct |
84 ms |
56992 KB |
Output is correct |
17 |
Correct |
93 ms |
59292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
51184 KB |
Output is correct |
2 |
Correct |
47 ms |
51184 KB |
Output is correct |
3 |
Incorrect |
68 ms |
51540 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
35468 KB |
Output is correct |
2 |
Correct |
16 ms |
35552 KB |
Output is correct |
3 |
Correct |
16 ms |
35488 KB |
Output is correct |
4 |
Correct |
16 ms |
35516 KB |
Output is correct |
5 |
Correct |
17 ms |
35472 KB |
Output is correct |
6 |
Correct |
16 ms |
35524 KB |
Output is correct |
7 |
Correct |
17 ms |
35540 KB |
Output is correct |
8 |
Correct |
17 ms |
35540 KB |
Output is correct |
9 |
Incorrect |
18 ms |
35556 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
35468 KB |
Output is correct |
2 |
Correct |
16 ms |
35552 KB |
Output is correct |
3 |
Correct |
16 ms |
35488 KB |
Output is correct |
4 |
Correct |
16 ms |
35516 KB |
Output is correct |
5 |
Correct |
17 ms |
35472 KB |
Output is correct |
6 |
Correct |
16 ms |
35524 KB |
Output is correct |
7 |
Correct |
17 ms |
35540 KB |
Output is correct |
8 |
Correct |
17 ms |
35540 KB |
Output is correct |
9 |
Incorrect |
18 ms |
35556 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
35468 KB |
Output is correct |
2 |
Correct |
16 ms |
35552 KB |
Output is correct |
3 |
Correct |
16 ms |
35488 KB |
Output is correct |
4 |
Correct |
16 ms |
35516 KB |
Output is correct |
5 |
Correct |
17 ms |
35472 KB |
Output is correct |
6 |
Correct |
16 ms |
35524 KB |
Output is correct |
7 |
Correct |
17 ms |
35540 KB |
Output is correct |
8 |
Correct |
17 ms |
35540 KB |
Output is correct |
9 |
Incorrect |
18 ms |
35556 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
51184 KB |
Output is correct |
2 |
Correct |
47 ms |
51184 KB |
Output is correct |
3 |
Incorrect |
68 ms |
51540 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
55640 KB |
Output is correct |
2 |
Correct |
97 ms |
58344 KB |
Output is correct |
3 |
Correct |
47 ms |
51108 KB |
Output is correct |
4 |
Correct |
46 ms |
51140 KB |
Output is correct |
5 |
Correct |
211 ms |
73344 KB |
Output is correct |
6 |
Correct |
234 ms |
81964 KB |
Output is correct |
7 |
Correct |
18 ms |
35548 KB |
Output is correct |
8 |
Correct |
134 ms |
61580 KB |
Output is correct |
9 |
Correct |
158 ms |
68884 KB |
Output is correct |
10 |
Correct |
84 ms |
56896 KB |
Output is correct |
11 |
Correct |
96 ms |
59908 KB |
Output is correct |
12 |
Correct |
21 ms |
35484 KB |
Output is correct |
13 |
Correct |
17 ms |
35540 KB |
Output is correct |
14 |
Correct |
18 ms |
35528 KB |
Output is correct |
15 |
Correct |
17 ms |
35536 KB |
Output is correct |
16 |
Correct |
47 ms |
51160 KB |
Output is correct |
17 |
Correct |
46 ms |
51120 KB |
Output is correct |
18 |
Correct |
84 ms |
56980 KB |
Output is correct |
19 |
Correct |
100 ms |
59988 KB |
Output is correct |
20 |
Correct |
90 ms |
56992 KB |
Output is correct |
21 |
Correct |
115 ms |
59392 KB |
Output is correct |
22 |
Correct |
84 ms |
56992 KB |
Output is correct |
23 |
Correct |
93 ms |
59292 KB |
Output is correct |
24 |
Correct |
51 ms |
51184 KB |
Output is correct |
25 |
Correct |
47 ms |
51184 KB |
Output is correct |
26 |
Incorrect |
68 ms |
51540 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412' |
27 |
Halted |
0 ms |
0 KB |
- |