#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1005;
ll p[N][N],dp[N][N][5];
ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) {
for (int i = 0;i < m; i++){
X[i]++,Y[i]++;
p[X[i]][Y[i]] += W[i];
}
for (int j = 1; j <= n; j++)
for (int i = 1; i <= n; i++)
p[j][i] += p[j][i - 1];
for (int j = 2; j <= n; j++){
for (int a = 0; a <= n; a++){
//update dp[j][a][0]
for (int b = a; b <= n; b++){
ll v = max(dp[j - 1][b][0],dp[j - 1][b][1]);
dp[j][a][0] = max(dp[j][a][0], v + p[j][b] - p[j][a]);
}
//update dp[j][a][1]
for (int b = 0; b <= a; b++){
ll v = dp[j - 1][b][1];
dp[j][a][1] = max(dp[j][a][1], v + p[j - 1][a] - p[j - 1][b]);
}
//c 0 a
if (j >= 3){
for (int c = 0; c <= n; c++){
ll v = max(dp[j - 2][c][0],dp[j - 2][c][1]);
dp[j][a][1] = max(dp[j][a][1], v + p[j - 1][max(a,c)]);
}
}
}
}
ll ans = 0;
for (int a = 0; a <= n; a++)
ans=max(ans,max(dp[n][a][0],dp[n][a][1]));
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
227 ms |
21324 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
255 ms |
26616 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
219 ms |
16384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
260 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
12 ms |
2576 KB |
Output is correct |
10 |
Correct |
83 ms |
6872 KB |
Output is correct |
11 |
Correct |
12 ms |
2540 KB |
Output is correct |
12 |
Correct |
83 ms |
6832 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
94 ms |
6900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
260 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
12 ms |
2576 KB |
Output is correct |
10 |
Correct |
83 ms |
6872 KB |
Output is correct |
11 |
Correct |
12 ms |
2540 KB |
Output is correct |
12 |
Correct |
83 ms |
6832 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
94 ms |
6900 KB |
Output is correct |
15 |
Correct |
83 ms |
6824 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
95 ms |
8532 KB |
Output is correct |
18 |
Correct |
100 ms |
8592 KB |
Output is correct |
19 |
Correct |
110 ms |
8536 KB |
Output is correct |
20 |
Correct |
95 ms |
8652 KB |
Output is correct |
21 |
Correct |
96 ms |
8516 KB |
Output is correct |
22 |
Correct |
114 ms |
10388 KB |
Output is correct |
23 |
Correct |
87 ms |
7152 KB |
Output is correct |
24 |
Correct |
91 ms |
7904 KB |
Output is correct |
25 |
Correct |
85 ms |
6852 KB |
Output is correct |
26 |
Correct |
86 ms |
7072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
260 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
12 ms |
2576 KB |
Output is correct |
10 |
Correct |
83 ms |
6872 KB |
Output is correct |
11 |
Correct |
12 ms |
2540 KB |
Output is correct |
12 |
Correct |
83 ms |
6832 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
94 ms |
6900 KB |
Output is correct |
15 |
Correct |
83 ms |
6824 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
95 ms |
8532 KB |
Output is correct |
18 |
Correct |
100 ms |
8592 KB |
Output is correct |
19 |
Correct |
110 ms |
8536 KB |
Output is correct |
20 |
Correct |
95 ms |
8652 KB |
Output is correct |
21 |
Correct |
96 ms |
8516 KB |
Output is correct |
22 |
Correct |
114 ms |
10388 KB |
Output is correct |
23 |
Correct |
87 ms |
7152 KB |
Output is correct |
24 |
Correct |
91 ms |
7904 KB |
Output is correct |
25 |
Correct |
85 ms |
6852 KB |
Output is correct |
26 |
Correct |
86 ms |
7072 KB |
Output is correct |
27 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
219 ms |
16384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
227 ms |
21324 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |