#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
using ll = long long;
int n, m;
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N, m = M;
int r = 0, c = 0;
for (int i = 0;i < m;i++) {
r = max(r, X[i] + 1);
c = max(c, Y[i] + 1);
}
c++;
r = min(n, r + 1);
vector<vector<int>> a(r + 1, vector<int>(c + 1, 0));
vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(r + 1, vector<ll>(c + 1, 0ll)));
for (int i = 0;i < m;i++) {
a[X[i] + 1][Y[i] + 1] = W[i];
}
ll mx;
for (int i = 2;i <= r;i++) {
// (0)
mx = 0;
for (int j = 0;j <= c;j++) {
mx = max(mx + a[i - 1][j], dp[0][i - 1][j]);
dp[0][i][j] = mx;
}
if (i >= 3) { // i - 2
ll sum = 0;
mx = 0;
for (int j = 0;j <= c;j++) {
mx = max({ mx, dp[0][i - 2][j], dp[1][i - 2][j] });
sum += a[i - 1][j];
dp[0][i][j] = max(dp[0][i][j], mx + sum);
}
mx = 0;
for (int j = c;j >= 0;j--) {
mx = max({ mx, dp[0][i - 2][j] + sum, dp[1][i - 2][j] + sum });
sum -= a[i - 1][j];
dp[0][i][j] = max(dp[0][i][j], mx);
}
}
// (1)
mx = 0;
for (int j = c;j >= 0;j--) {
mx = max({ mx, dp[0][i - 1][j], dp[1][i - 1][j] });
dp[1][i][j] = mx;
mx += a[i][j];
}
}
ll ans = 0;
for (int i = 1;i <= r;i++) {
for (int j = 0;j <= c;j++) {
ans = max({ ans, dp[0][i][j], dp[1][i][j] });
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
10232 KB |
Output is correct |
2 |
Correct |
22 ms |
11732 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
6 ms |
9424 KB |
Output is correct |
5 |
Runtime error |
910 ms |
2097152 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
14800 KB |
Output is correct |
3 |
Correct |
42 ms |
16740 KB |
Output is correct |
4 |
Correct |
18 ms |
10236 KB |
Output is correct |
5 |
Correct |
23 ms |
11732 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
9424 KB |
Output is correct |
12 |
Correct |
19 ms |
12828 KB |
Output is correct |
13 |
Correct |
24 ms |
14540 KB |
Output is correct |
14 |
Correct |
20 ms |
12796 KB |
Output is correct |
15 |
Correct |
22 ms |
14184 KB |
Output is correct |
16 |
Correct |
26 ms |
12788 KB |
Output is correct |
17 |
Correct |
29 ms |
14156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
22248 KB |
Output is correct |
3 |
Correct |
30 ms |
21052 KB |
Output is correct |
4 |
Correct |
27 ms |
20984 KB |
Output is correct |
5 |
Correct |
43 ms |
24568 KB |
Output is correct |
6 |
Correct |
40 ms |
24572 KB |
Output is correct |
7 |
Correct |
48 ms |
24660 KB |
Output is correct |
8 |
Correct |
49 ms |
24692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
10 ms |
3932 KB |
Output is correct |
18 |
Correct |
11 ms |
3932 KB |
Output is correct |
19 |
Correct |
11 ms |
3932 KB |
Output is correct |
20 |
Correct |
9 ms |
3792 KB |
Output is correct |
21 |
Correct |
9 ms |
2652 KB |
Output is correct |
22 |
Correct |
18 ms |
5100 KB |
Output is correct |
23 |
Correct |
3 ms |
2960 KB |
Output is correct |
24 |
Correct |
7 ms |
3608 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
10 ms |
3932 KB |
Output is correct |
18 |
Correct |
11 ms |
3932 KB |
Output is correct |
19 |
Correct |
11 ms |
3932 KB |
Output is correct |
20 |
Correct |
9 ms |
3792 KB |
Output is correct |
21 |
Correct |
9 ms |
2652 KB |
Output is correct |
22 |
Correct |
18 ms |
5100 KB |
Output is correct |
23 |
Correct |
3 ms |
2960 KB |
Output is correct |
24 |
Correct |
7 ms |
3608 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
3164 KB |
Output is correct |
27 |
Correct |
195 ms |
247556 KB |
Output is correct |
28 |
Correct |
48 ms |
20872 KB |
Output is correct |
29 |
Correct |
217 ms |
215924 KB |
Output is correct |
30 |
Correct |
256 ms |
254584 KB |
Output is correct |
31 |
Correct |
257 ms |
254580 KB |
Output is correct |
32 |
Correct |
55 ms |
15712 KB |
Output is correct |
33 |
Correct |
250 ms |
254576 KB |
Output is correct |
34 |
Correct |
250 ms |
254548 KB |
Output is correct |
35 |
Correct |
30 ms |
16728 KB |
Output is correct |
36 |
Correct |
123 ms |
102008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
22248 KB |
Output is correct |
3 |
Correct |
30 ms |
21052 KB |
Output is correct |
4 |
Correct |
27 ms |
20984 KB |
Output is correct |
5 |
Correct |
43 ms |
24568 KB |
Output is correct |
6 |
Correct |
40 ms |
24572 KB |
Output is correct |
7 |
Correct |
48 ms |
24660 KB |
Output is correct |
8 |
Correct |
49 ms |
24692 KB |
Output is correct |
9 |
Runtime error |
867 ms |
2097152 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
10232 KB |
Output is correct |
2 |
Correct |
22 ms |
11732 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
6 ms |
9424 KB |
Output is correct |
5 |
Runtime error |
910 ms |
2097152 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |