#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 <set <int> > vec(n + 2);
for(int i = 0; i < m; i++){
vec[X[i] + 1].insert(Y[i] + 1);
val[{X[i] + 1, Y[i] + 1}] = W[i];
}
for(int i = 0; i <= n + 1; i++){
vec[i].insert(0);
vec[i].insert(n);
}
for(int i = 1; i <= n + 1; i++){
if(i > 1){
set <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();
if(last == -1){
dp[{i, j}] = max(DP[{i - 2, a}] + val[{i, j}], dp[{i - 2, b}] + val[{i, j}]);
}
else{
int v = *vec[i - 1].upper_bound(j);
dp[{i, j}] = max(last + val[{i, j}], dp[{i - 1, v}] + val[{i, j}]);
}
last = dp[{i, j}];
}
}
set <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, x}] + v;
}
else{
int x =*(--vec[i].lower_bound(j));
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:34:17: warning: unused variable 'ind' [-Wunused-variable]
34 | int ind = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
448 ms |
67632 KB |
Output is correct |
2 |
Correct |
532 ms |
77768 KB |
Output is correct |
3 |
Correct |
297 ms |
51864 KB |
Output is correct |
4 |
Correct |
296 ms |
51916 KB |
Output is correct |
5 |
Execution timed out |
1099 ms |
148200 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
296 ms |
51888 KB |
Output is correct |
2 |
Correct |
301 ms |
51920 KB |
Output is correct |
3 |
Correct |
306 ms |
60976 KB |
Output is correct |
4 |
Correct |
335 ms |
61484 KB |
Output is correct |
5 |
Correct |
577 ms |
77780 KB |
Output is correct |
6 |
Correct |
534 ms |
77712 KB |
Output is correct |
7 |
Correct |
544 ms |
77808 KB |
Output is correct |
8 |
Correct |
544 ms |
77704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
296 ms |
51888 KB |
Output is correct |
2 |
Correct |
301 ms |
51920 KB |
Output is correct |
3 |
Correct |
306 ms |
60976 KB |
Output is correct |
4 |
Correct |
335 ms |
61484 KB |
Output is correct |
5 |
Correct |
577 ms |
77780 KB |
Output is correct |
6 |
Correct |
534 ms |
77712 KB |
Output is correct |
7 |
Correct |
544 ms |
77808 KB |
Output is correct |
8 |
Correct |
544 ms |
77704 KB |
Output is correct |
9 |
Incorrect |
567 ms |
83948 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
448 ms |
67632 KB |
Output is correct |
2 |
Correct |
532 ms |
77768 KB |
Output is correct |
3 |
Correct |
297 ms |
51864 KB |
Output is correct |
4 |
Correct |
296 ms |
51916 KB |
Output is correct |
5 |
Execution timed out |
1099 ms |
148200 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |