#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.begin(), vec.end());
}
for(int i = 1; i <= n + 1; i++){
if(i > 1){
vector <int> :: reverse_iterator rit;
int ind = 0;
ll last = -1;
for(rit = vec[i].rbegin(); rit != vec[i].rend(); rit++){
int j = *rit;
int a = *vec[i - 2].rbegin();
int b = *vec[i - 2].begin();
int v = val[{i, j}];
if(last == -1){
dp[{i, j}] = max(DP[{i - 2, a}] + v, dp[{i - 2, b}] + 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}];
}
}
vector <int> :: iterator it;
ll last = -1;
for(it = vec[i].begin(); it != vec[i].end(); it++){
int j = *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 = vec[i - 1][x];
DP[{i, j}] = max(DP[{i - 1, x}], last) + v;
}
last = DP[{i, j}];
}
}
ll ans = DP[{n + 1, 0}];
for(int i = 1; i <= n; i++){
ans = max(ans, DP[{n, 0}]);
}
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
9680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
2644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
2644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
9680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |