#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const long long inf = -(1LL << 60);
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
vector p(n, vector<int>(n + 1));
for (int i = 0; i < m; i++) {
p[x[i]][y[i] + 1] = w[i];
}
vector s(n, vector<long long>(n + 2));
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
s[i][j + 1] = s[i][j] + p[i][j];
}
}
auto range_sum = [&](int i, int l, int r) -> long long {
if (i == -1) {
return 0;
}
return s[i][r + 1] - s[i][l + 1];
};
vector dp(n + 1, array<long long, 2>{inf, inf});
dp[0] = {0, 0};
for (int i = 0; i < n; i++) {
auto pd = dp;
vector<long long> pmax(n + 2, inf);
for (int j = 0; j <= n; j++) {
pmax[j + 1] = max(pmax[j], pd[j][0] + range_sum(i - 1, j, n));
}
vector<long long> smax(n + 2, inf);
for (int j = n; j >= 0; j--) {
smax[j] = max(smax[j + 1], max(pd[j][0], pd[j][1]) - range_sum(i, j, n));
}
dp = vector(n + 1, array<long long, 2>{inf, inf});
for (int j = 0; j <= n; j++) {
dp[0][0] = max(dp[0][0], max(pd[j][0], pd[j][1]));
dp[0][1] = max(dp[0][1], max(pd[j][0], pd[j][1]) + range_sum(i, 0, j));
}
for (int j = 1; j <= n; j++) {
dp[j][0] = max(dp[j][0], max(pd[0][1], pd[0][0] + range_sum(i - 1, 0, j)));
dp[j][1] = max(dp[j][1], max(pd[0][1], pd[0][0] + range_sum(i - 1, 0, j)));
dp[j][0] = max(dp[j][0], pmax[j + 1] - range_sum(i - 1, j, n));
dp[j][1] = max(dp[j][1], smax[j] + range_sum(i, j, n));
// for (int k = 1; k <= j; k++) {
// dp[j][0] = max(dp[j][0], pd[k][0] + range_sum(i - 1, k, j));
// }
// for (int k = j; k <= n; k++) {
// dp[j][1] = max(dp[j][1], max(pd[k][0], pd[k][1]) + range_sum(i, j, k));
// }
}
}
long long ans = inf;
for (int i = 0; i <= n; i++) {
ans = max(ans, max(dp[i][0], dp[i][1]));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1179 ms |
2085424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
846 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
794 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
1364 KB |
Output is correct |
15 |
Correct |
3 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
14 ms |
2392 KB |
Output is correct |
18 |
Correct |
13 ms |
2372 KB |
Output is correct |
19 |
Correct |
13 ms |
2368 KB |
Output is correct |
20 |
Correct |
17 ms |
2376 KB |
Output is correct |
21 |
Correct |
17 ms |
2376 KB |
Output is correct |
22 |
Correct |
25 ms |
3416 KB |
Output is correct |
23 |
Correct |
4 ms |
1496 KB |
Output is correct |
24 |
Correct |
10 ms |
2068 KB |
Output is correct |
25 |
Correct |
2 ms |
1364 KB |
Output is correct |
26 |
Correct |
4 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
1364 KB |
Output is correct |
15 |
Correct |
3 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
14 ms |
2392 KB |
Output is correct |
18 |
Correct |
13 ms |
2372 KB |
Output is correct |
19 |
Correct |
13 ms |
2368 KB |
Output is correct |
20 |
Correct |
17 ms |
2376 KB |
Output is correct |
21 |
Correct |
17 ms |
2376 KB |
Output is correct |
22 |
Correct |
25 ms |
3416 KB |
Output is correct |
23 |
Correct |
4 ms |
1496 KB |
Output is correct |
24 |
Correct |
10 ms |
2068 KB |
Output is correct |
25 |
Correct |
2 ms |
1364 KB |
Output is correct |
26 |
Correct |
4 ms |
1500 KB |
Output is correct |
27 |
Correct |
188 ms |
106508 KB |
Output is correct |
28 |
Correct |
66 ms |
12056 KB |
Output is correct |
29 |
Correct |
291 ms |
113492 KB |
Output is correct |
30 |
Correct |
252 ms |
113532 KB |
Output is correct |
31 |
Correct |
266 ms |
113484 KB |
Output is correct |
32 |
Correct |
81 ms |
10848 KB |
Output is correct |
33 |
Correct |
290 ms |
113520 KB |
Output is correct |
34 |
Correct |
289 ms |
113392 KB |
Output is correct |
35 |
Correct |
233 ms |
109132 KB |
Output is correct |
36 |
Correct |
266 ms |
113484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
794 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1179 ms |
2085424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |