#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define epb emplace_back
#define f first
#define s second
#include <vector>
using namespace std;
map<pii, ll> val;
map <pii, ll> dp;
map <pii, ll> DP;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
int n = N;
int m = M;
vector <vector <int> > vec(n + 2);
for(int i = 0; i < m; i++){
vec[X[i] + 1].pb(Y[i] + 1);
val[{X[i] + 1, Y[i] + 1}] = W[i];
}
for(int i = 0; i <= n + 1; i++){
vec[i].pb(0);
vec[i].pb(n + 1);
sort(vec[i].begin(), vec[i].end());
}
for(int i = 1; i <= n + 1; i++){
if(i > 1){
int ind = 0;
ll last = -1;
int rit;
for(rit = vec[i].size() - 1; rit >= 0; rit--){
int j = vec[i][rit];
ll v = val[{i, j}];
if(last == -1){
dp[{i, j}] = max(DP[{i - 2, n + 1}] + v, dp[{i - 2, 0}] + v);
}
else{
int vv = upper_bound(vec[i - 1].begin(), vec[i - 1].end(), j) - vec[i - 1].begin();
vv = vec[i - 1][vv];
dp[{i, j}] = max(last + v, dp[{i - 1, vv}] + v);
}
last = dp[{i, j}];
}
}
int it = 0;
ll last = -1;
for(it = 0; it < vec[i].size(); it++){
int j = vec[i][it];
ll v = val[{i, j}];
if(last == -1){
//int x = *vec[i - 1].begin();
DP[{i, j}] = dp[{i - 1, 0}] + v;
}
else{
int x = lower_bound(vec[i - 1].begin(), vec[i - 1].end(), j) - vec[i - 1].begin();
x--;
x = vec[i - 1][x];
DP[{i, j}] = max(DP[{i - 1, x}], last) + v;
}
last = DP[{i, j}];
}
}
ll ans = max(dp[{n, 0}], DP[{n, n + 1}]);
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:35:17: warning: unused variable 'ind' [-Wunused-variable]
35 | int ind = 0;
| ^~~
fish.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(it = 0; it < vec[i].size(); it++){
| ~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
339 ms |
51328 KB |
Output is correct |
2 |
Correct |
408 ms |
58560 KB |
Output is correct |
3 |
Correct |
262 ms |
43300 KB |
Output is correct |
4 |
Correct |
276 ms |
43296 KB |
Output is correct |
5 |
Correct |
998 ms |
107916 KB |
Output is correct |
6 |
Correct |
856 ms |
108216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
580 ms |
73488 KB |
Output is correct |
3 |
Correct |
729 ms |
86584 KB |
Output is correct |
4 |
Correct |
353 ms |
51376 KB |
Output is correct |
5 |
Correct |
405 ms |
58800 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
43336 KB |
Output is correct |
2 |
Correct |
257 ms |
43260 KB |
Output is correct |
3 |
Correct |
281 ms |
50360 KB |
Output is correct |
4 |
Correct |
283 ms |
50836 KB |
Output is correct |
5 |
Incorrect |
535 ms |
64448 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673122841934' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
43336 KB |
Output is correct |
2 |
Correct |
257 ms |
43260 KB |
Output is correct |
3 |
Correct |
281 ms |
50360 KB |
Output is correct |
4 |
Correct |
283 ms |
50836 KB |
Output is correct |
5 |
Incorrect |
535 ms |
64448 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673122841934' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
339 ms |
51328 KB |
Output is correct |
2 |
Correct |
408 ms |
58560 KB |
Output is correct |
3 |
Correct |
262 ms |
43300 KB |
Output is correct |
4 |
Correct |
276 ms |
43296 KB |
Output is correct |
5 |
Correct |
998 ms |
107916 KB |
Output is correct |
6 |
Correct |
856 ms |
108216 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
580 ms |
73488 KB |
Output is correct |
9 |
Correct |
729 ms |
86584 KB |
Output is correct |
10 |
Correct |
353 ms |
51376 KB |
Output is correct |
11 |
Correct |
405 ms |
58800 KB |
Output is correct |
12 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
13 |
Halted |
0 ms |
0 KB |
- |