#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
ll max_weights(int N, int M, vector <int> x, vector <int> y, vector <int> w) {
vector <vector <ll>> mat(N + 2, vector <ll> (N));
for (int i = 0; i < M; i++)
mat[x[i] + 1][y[i]] = w[i];
vector <ll> sum(N + 2);
vector <ll> maks(N + 2), mini(N + 2);
for (int i = 1; i < N + 2; i++) {
ll curr = 0;
for (int j = 0; j < N; j++) {
sum[i] += mat[i][j];
curr += mat[i - 1][j] - mat[i][j];
maks[i] = max(maks[i], curr);
mini[i] = max(mini[i], -curr);
}
}
auto make_sum = [&](vector <ll> &v) {
for (int i = 1; i < v.size(); i++)
v[i] += v[i - 1];
};
make_sum(maks);
make_sum(mini);
auto get_sum = [&](const vector <ll> &pref, int lo, int hi) {
return pref[hi] - (lo ? pref[lo - 1] : 0);
};
vector <vector <ll>> trans(N + 2, vector <ll> (N + 2));
for (int i = 0; i < N + 2; i++)
for (int j = i + 1; j < N + 2; j++) {
if (i)
trans[i][j] = max(trans[i][j], sum[i + 1] + get_sum(mini, i + 2, j));
if (j <= N)
trans[i][j] = max(trans[i][j], sum[j - 1] + get_sum(maks, i + 1, j - 1));
for (int k = i + 1; k < j; k++)
trans[i][j] = max(trans[i][j], get_sum(maks, i + 1, k - 1) + get_sum(mini, k + 2, j) + sum[k - 1] + sum[k + 1]);
}
vector <ll> dp(N + 2);
for (int i = 0; i < N + 2; i++)
for (int j = i; j >= 0; j--)
dp[i] = max(dp[i], (j ? dp[j - 1] : 0) + trans[j][i]);
return dp[N + 1];
}
Compilation message
fish.cpp: In lambda function:
fish.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
802 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
783 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
730 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
10 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
9 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
10 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
9 ms |
1748 KB |
Output is correct |
15 |
Correct |
9 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
19 ms |
2760 KB |
Output is correct |
18 |
Correct |
20 ms |
2764 KB |
Output is correct |
19 |
Correct |
20 ms |
2752 KB |
Output is correct |
20 |
Correct |
19 ms |
2760 KB |
Output is correct |
21 |
Correct |
23 ms |
2772 KB |
Output is correct |
22 |
Correct |
30 ms |
3796 KB |
Output is correct |
23 |
Correct |
10 ms |
1876 KB |
Output is correct |
24 |
Correct |
17 ms |
2388 KB |
Output is correct |
25 |
Correct |
9 ms |
1876 KB |
Output is correct |
26 |
Correct |
10 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
10 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
9 ms |
1748 KB |
Output is correct |
15 |
Correct |
9 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
19 ms |
2760 KB |
Output is correct |
18 |
Correct |
20 ms |
2764 KB |
Output is correct |
19 |
Correct |
20 ms |
2752 KB |
Output is correct |
20 |
Correct |
19 ms |
2760 KB |
Output is correct |
21 |
Correct |
23 ms |
2772 KB |
Output is correct |
22 |
Correct |
30 ms |
3796 KB |
Output is correct |
23 |
Correct |
10 ms |
1876 KB |
Output is correct |
24 |
Correct |
17 ms |
2388 KB |
Output is correct |
25 |
Correct |
9 ms |
1876 KB |
Output is correct |
26 |
Correct |
10 ms |
1876 KB |
Output is correct |
27 |
Execution timed out |
1098 ms |
141712 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
730 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
802 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |