#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> trio;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
vector<ll> ans_col(N);
vector<vector<pii>> val(N);
vector<vector<ll>> dp[2];
dp[0].resize(N); // x-1 < x
dp[1].resize(N); // x-1 > x
for(int i = 0; i < M; i++) val[X[i]].pb({Y[i], W[i]});
dp[0][0].resize(sz(val[0])+1, 0);
dp[1][0].resize(sz(val[0])+1, 0);
for(int x = 1; x < N; x++) {
sort(all(val[x]));
reverse(all(val[x]));
dp[0][x].resize(sz(val[x])+1);
dp[1][x].resize(sz(val[x])+1);
// >
for(int i = 0, j = 0; i < sz(val[x]); i++) {
auto [y,w] = val[x][i];
if(i != 0) dp[1][x][i+1] = dp[1][x][i] + w;
while(j < sz(val[x-1]) and val[x-1][j].fr > y) j++;
dp[1][x][i+1] = max(dp[1][x][i+1], dp[1][x-1][j] + w); // LEMBRAR DE dp[1][x][j] max= dp[1][x][j-1]
//cout << "1x = " << x << ", i = " << i << ", y = " << y << ", w = " << w << ", dp = " << dp[1][x][i+1] << "\n";
}
// <
ll w = 0, w1 = 0;
for(int i = sz(val[x]) - 1, j = sz(val[x-1]) - 1, y; i >= -1; i--) {
if(i >= 0) y = val[x][i].fr;
else y = N;
while(j >= 0 and val[x-1][j].fr < y) {
w = max(w, dp[0][x-1][j+1]);
w += val[x-1][j].sc;
w1 = max(w1, dp[1][x-1][j+1]);
j--;
}
dp[0][x][i+1] = max({dp[0][x][i+1], w, w1});
}
dp[1][x][0] = max(dp[1][x][0], dp[0][x][0]);
for(int i = 1; i <= sz(val[x]); i++)
dp[1][x][i] = max({dp[1][x][i], dp[1][x][i-1], dp[0][x][i]});
ans_col[x] = dp[1][x][sz(val[x])];
}
return ans_col[N-1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
16836 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
48 ms |
20504 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
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 |
412 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
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 |
412 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
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 |
412 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
16836 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |