#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll pref[305][305], dp[305][305][2];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
for(int i=0; i<M; i++) pref[X[i]+1][Y[i]+1] += W[i];
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++) pref[i][j] += pref[i][j-1];
for(int i=2; i<=N; i++) {
for(int j=0; j<=N; j++) {
for(int k=0; k<=N; k++) {
if(j >= k) dp[i][j][1] = max(dp[i][j][1], dp[i-1][k][1] + pref[i-1][j] - pref[i-1][k]);
if(j <= k) dp[i][j][0] = max(dp[i][j][0], max(dp[i-1][k][0], dp[i-1][k][1]) + pref[i][k] - pref[i][j]);
if(i >= 3) dp[i][j][0] = max(dp[i][j][0], max(dp[i-2][k][0], dp[i-2][k][1]) + max(pref[i-1][j], pref[i-1][k]));
if(i >= 3) dp[i][j][1] = max(dp[i][j][1], max(dp[i-2][k][0], dp[i-2][k][1]) + max(pref[i-1][j], pref[i-1][k]));
}
}
}
ll ans = 0;
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++) ans = max({ ans, dp[i][j][0] + pref[i+1][j], dp[i][j][1] + pref[i+1][j] });
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
6736 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
29 ms |
11708 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
10 ms |
1400 KB |
Output is correct |
10 |
Correct |
73 ms |
2644 KB |
Output is correct |
11 |
Correct |
11 ms |
1368 KB |
Output is correct |
12 |
Correct |
75 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
79 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
10 ms |
1400 KB |
Output is correct |
10 |
Correct |
73 ms |
2644 KB |
Output is correct |
11 |
Correct |
11 ms |
1368 KB |
Output is correct |
12 |
Correct |
75 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
79 ms |
2512 KB |
Output is correct |
15 |
Correct |
75 ms |
2384 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
81 ms |
4184 KB |
Output is correct |
18 |
Correct |
80 ms |
4176 KB |
Output is correct |
19 |
Correct |
81 ms |
4180 KB |
Output is correct |
20 |
Correct |
81 ms |
4176 KB |
Output is correct |
21 |
Correct |
81 ms |
4176 KB |
Output is correct |
22 |
Correct |
88 ms |
6260 KB |
Output is correct |
23 |
Correct |
77 ms |
2896 KB |
Output is correct |
24 |
Correct |
79 ms |
3664 KB |
Output is correct |
25 |
Correct |
77 ms |
2384 KB |
Output is correct |
26 |
Correct |
75 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
10 ms |
1400 KB |
Output is correct |
10 |
Correct |
73 ms |
2644 KB |
Output is correct |
11 |
Correct |
11 ms |
1368 KB |
Output is correct |
12 |
Correct |
75 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
79 ms |
2512 KB |
Output is correct |
15 |
Correct |
75 ms |
2384 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
81 ms |
4184 KB |
Output is correct |
18 |
Correct |
80 ms |
4176 KB |
Output is correct |
19 |
Correct |
81 ms |
4180 KB |
Output is correct |
20 |
Correct |
81 ms |
4176 KB |
Output is correct |
21 |
Correct |
81 ms |
4176 KB |
Output is correct |
22 |
Correct |
88 ms |
6260 KB |
Output is correct |
23 |
Correct |
77 ms |
2896 KB |
Output is correct |
24 |
Correct |
79 ms |
3664 KB |
Output is correct |
25 |
Correct |
77 ms |
2384 KB |
Output is correct |
26 |
Correct |
75 ms |
2900 KB |
Output is correct |
27 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
6736 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |