#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], suf[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];
}
for(int i = 0; i <= n; ++i) dp[0][i] = pref[1][i], dp2[0][i] = pref[1][i];
mx[0] = pref[1][n];
suf[0][n + 1] = 0;
for(int j = n; j >= 0 ;--j) suf[0][j] = max(suf[0][j + 1], dp[0][j]);
for(int i = 1; i < n; ++i){
mx[i] = 0;
ll mx_pref = 0, mx_pref2 = 0;
for(int j = 0; j <= n; ++j){
ll add = pref[i + 1][j] + pref[i - 1][j];
dp[i][j] = add;
if(i > 2) dp[i][j] = max(dp[i][j], mx[i - 3] + add);
dp2[i][j] = dp[i][j];
}
for(int j = 0; j <= n; ++j){
ll add = pref[i + 1][j] + pref[i - 1][j];
// cout << i << ' ' << j << ' ' << add1 << ' ' <<add2 << ' ';
ll x = add - pref[i - 1][j] - pref[i][j];
// for(int j2 = j + 1; j2 <= n; ++j2){
// dp[i][j] = max(dp[i][j], dp[i - 1][j2] + x);
// }
mx_pref2 = max(mx_pref2, dp2[i - 1][j] - pref[i - 1][j] - pref[i][j]);
dp[i][j] = max(dp[i][j], mx_pref2 + add);
dp2[i][j] = max(dp2[i][j], mx_pref2 + add);
dp[i][j] = max(dp[i][j], suf[i - 1][j] + x);
if(i > 1){
mx_pref = max(mx_pref, dp[i - 2][j] - pref[i - 1][j]);
dp[i][j] = max(dp[i][j], mx_pref + add);
dp[i][j] = max(dp[i][j], suf[i - 2][j] - pref[i - 1][j]);
dp2[i][j] = max(dp2[i][j], mx_pref + add);
dp2[i][j] = max(dp2[i][j], suf[i - 2][j] - pref[i - 1][j]);
}
// cout << dp[i][j] << '\n';
}
for(int j = 0; j <= n; ++j) mx[i] = max(mx[i], dp[i][j]);
suf[i][n + 1] = 0;
// suf2[i][n] = dp[i][n];
for(int j = n; j >= 0 ;--j) suf[i][j] = max(suf[i][j + 1], dp[i][j]);
// for(int j = n-1; j >= 0 ;--j) suf2[i][j] = max(suf2[i][j + 1], dp[i][j]);
// en;
}
ll ans = mx[n - 1];
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
904 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
709 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
711 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
444 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
3676 KB |
Output is correct |
10 |
Correct |
5 ms |
8700 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
4 ms |
8644 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
3 ms |
8844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
444 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
3676 KB |
Output is correct |
10 |
Correct |
5 ms |
8700 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
4 ms |
8644 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
3 ms |
8844 KB |
Output is correct |
15 |
Correct |
4 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
1884 KB |
Output is correct |
17 |
Correct |
14 ms |
10692 KB |
Output is correct |
18 |
Correct |
11 ms |
10440 KB |
Output is correct |
19 |
Correct |
13 ms |
10436 KB |
Output is correct |
20 |
Correct |
11 ms |
10444 KB |
Output is correct |
21 |
Correct |
11 ms |
10588 KB |
Output is correct |
22 |
Correct |
17 ms |
12224 KB |
Output is correct |
23 |
Correct |
4 ms |
9100 KB |
Output is correct |
24 |
Correct |
7 ms |
9868 KB |
Output is correct |
25 |
Correct |
4 ms |
8796 KB |
Output is correct |
26 |
Correct |
5 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
444 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
3676 KB |
Output is correct |
10 |
Correct |
5 ms |
8700 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
4 ms |
8644 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
3 ms |
8844 KB |
Output is correct |
15 |
Correct |
4 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
1884 KB |
Output is correct |
17 |
Correct |
14 ms |
10692 KB |
Output is correct |
18 |
Correct |
11 ms |
10440 KB |
Output is correct |
19 |
Correct |
13 ms |
10436 KB |
Output is correct |
20 |
Correct |
11 ms |
10444 KB |
Output is correct |
21 |
Correct |
11 ms |
10588 KB |
Output is correct |
22 |
Correct |
17 ms |
12224 KB |
Output is correct |
23 |
Correct |
4 ms |
9100 KB |
Output is correct |
24 |
Correct |
7 ms |
9868 KB |
Output is correct |
25 |
Correct |
4 ms |
8796 KB |
Output is correct |
26 |
Correct |
5 ms |
9052 KB |
Output is correct |
27 |
Correct |
161 ms |
353236 KB |
Output is correct |
28 |
Correct |
51 ms |
43412 KB |
Output is correct |
29 |
Correct |
209 ms |
365952 KB |
Output is correct |
30 |
Correct |
220 ms |
365912 KB |
Output is correct |
31 |
Correct |
212 ms |
365908 KB |
Output is correct |
32 |
Correct |
55 ms |
33116 KB |
Output is correct |
33 |
Correct |
210 ms |
365800 KB |
Output is correct |
34 |
Correct |
211 ms |
365912 KB |
Output is correct |
35 |
Correct |
184 ms |
358028 KB |
Output is correct |
36 |
Correct |
210 ms |
365808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
711 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
904 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |