#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int n,int m,vector<int>x,vector<int>y,vector<int>w){
long long dp[n+2][n+2][2]{};
long long sum[n+2][n+2]{};
for(int i = 0; i < m; i++) x[i] += 1;
for(int i = 0; i < m; i++) y[i] += 1;
for(int i = 0; i < m; i++) sum[x[i]][y[i]] += w[i];
long long ans = 0;
for(int i = 0; i <= n+1; i++){
for(int j = n; j >= 0; j--){
sum[i][j] += sum[i][j+1];
}
}
for(int i = 1; i <= n+1; i++){
for(int j = 0; j < 2; j++){
dp[0][i][j] = -1e18;
}
}
dp[0][0][1] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= n+1; j++){
for(int k = 0; k <= n+1; k++){
long long now = dp[i-1][j][1];
if(k > j){
now += sum[i-1][j]-sum[i-1][k];
}
if(j > k){
now += sum[i][k]-sum[i][j];
}
// int cur = k;
// while(cur > j) now += sum[i-1][cur--];
// cur = j;
// while(cur > k) now += sum[i][cur--];
ans = max(ans,now);
if(k > j) dp[i][k][1] = max(dp[i][k][1],now);
else if (k < j){
dp[i][k][0] = max(dp[i][k][0],now);
now -= dp[i-1][j][1];
now += dp[i-1][j][0];
ans = max(ans,now);
dp[i][k][0] = max(dp[i][k][0],now);
}
else{
dp[i][k][1] = max(dp[i][k][1],now);
dp[i][k][0] = max(dp[i][k][0],now);
now -= dp[i-1][j][1];
now += dp[i-1][j][0];
ans = max(ans,now);
dp[i][k][0] = max(dp[i][k][0],now);
dp[i][k][1] = max(dp[i][k][1],now);
}
}
dp[i][0][1] = max({dp[i][0][1],dp[i-1][j][1],dp[i-1][j][0]});
}
}
return ans;
}
// int main(){
// cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1107 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1039 ms |
2097152 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
8 ms |
992 KB |
Output is correct |
10 |
Correct |
53 ms |
2600 KB |
Output is correct |
11 |
Correct |
8 ms |
860 KB |
Output is correct |
12 |
Correct |
53 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
54 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
8 ms |
992 KB |
Output is correct |
10 |
Correct |
53 ms |
2600 KB |
Output is correct |
11 |
Correct |
8 ms |
860 KB |
Output is correct |
12 |
Correct |
53 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
54 ms |
2396 KB |
Output is correct |
15 |
Correct |
52 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
63 ms |
4424 KB |
Output is correct |
18 |
Correct |
63 ms |
4160 KB |
Output is correct |
19 |
Correct |
62 ms |
4184 KB |
Output is correct |
20 |
Correct |
62 ms |
4184 KB |
Output is correct |
21 |
Correct |
62 ms |
4188 KB |
Output is correct |
22 |
Correct |
71 ms |
6076 KB |
Output is correct |
23 |
Correct |
57 ms |
2904 KB |
Output is correct |
24 |
Correct |
59 ms |
3676 KB |
Output is correct |
25 |
Correct |
53 ms |
2396 KB |
Output is correct |
26 |
Correct |
56 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
8 ms |
992 KB |
Output is correct |
10 |
Correct |
53 ms |
2600 KB |
Output is correct |
11 |
Correct |
8 ms |
860 KB |
Output is correct |
12 |
Correct |
53 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
54 ms |
2396 KB |
Output is correct |
15 |
Correct |
52 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
63 ms |
4424 KB |
Output is correct |
18 |
Correct |
63 ms |
4160 KB |
Output is correct |
19 |
Correct |
62 ms |
4184 KB |
Output is correct |
20 |
Correct |
62 ms |
4184 KB |
Output is correct |
21 |
Correct |
62 ms |
4188 KB |
Output is correct |
22 |
Correct |
71 ms |
6076 KB |
Output is correct |
23 |
Correct |
57 ms |
2904 KB |
Output is correct |
24 |
Correct |
59 ms |
3676 KB |
Output is correct |
25 |
Correct |
53 ms |
2396 KB |
Output is correct |
26 |
Correct |
56 ms |
2908 KB |
Output is correct |
27 |
Execution timed out |
1085 ms |
211892 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1107 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |