#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define en cout << '\n'
#define pi pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
const int N = 3005;
ll dp[N][N], pref[N][N], mx[N], dp2[N][N];
long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
vector<vector<ll>> a(n + 1, vector<ll>(n + 1));
for(int i = 0; i < m; ++i){
a[X[i]][Y[i] + 1] = W[i];
}
for(int i = 0; i < n; ++i){
pref[i][0] = a[i][0];
for(int j = 1; j <= n; ++j) pref[i][j] = pref[i][j - 1] + a[i][j], dp2[i][j] = 0;
}
for(int i = 0; i < n; ++i) dp[0][i] = pref[1][i], dp2[0][i] = pref[1][i];
mx[0] = pref[1][n];
for(int i = 1; i < n; ++i){
mx[i] = 0;
for(int j = 0; j <= n; ++j){
ll add1 = pref[i + 1][j];
ll add2 = pref[i - 1][j];
dp[i][j] = add1 + add2;
if(i > 2) dp[i][j] = max(dp[i][j], mx[i - 3] + add1 + add2);
// cout << i << ' ' << j << ' ' << add1 << ' ' <<add2 << ' ';
dp2[i][j] = dp[i][j];
for(int j2 = 0; j2 <= n; ++j2){
if(i > 1){
dp[i][j] = max(dp[i][j], dp[i - 2][j2] - pref[i - 1][min(j, j2)] + add1 + add2);
}
if(i > 1){
for(int j3 = 0; j3 <= j2; ++j3)
dp[i][j] = max(dp[i][j], dp[i - 2][j3] + add1 + add2 - pref[i - 1][min(j, j2)] - pref[i][min(j, j2)] - pref[i - 1][j3]);
}else{
dp[i][j] = max(dp[i][j], dp[i - 1][j2] + add1 + add2 - pref[i - 1][min(j,j2)] - pref[i][min(j,j2)]);
}
}
mx[i] = max(mx[i], dp[i][j]);
// cout << dp[i][j] << '\n';
}
// en;
}
ll ans = mx[n - 1];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
722 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
677 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
677 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
722 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |