#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
using namespace std;
constexpr static int SIZE = 3001;
int dp[SIZE][SIZE][2];
int grid[SIZE][SIZE];
int max_weights(int32_t n, int32_t m, vector<int32_t> x, vector<int32_t> y, vector<int32_t> w)
{
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k < 2; k++)
dp[i][j][k] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
grid[i][j] = 0;
for (int i = 0; i < m; i++)
grid[x[i]][y[i]] = w[i];
for (int i = 1; i <= n; i++)
dp[1][i][0] = dp[1][i-1][0] + grid[0][i-1];
for (int i = n-1; i >= 0; i--)
dp[1][i][1] = dp[1][i+1][1] + grid[1][i];
for (int i = 2; i < n; i++)
{
vector<int> b_l(n+1), b_h(n+1);
vector<int> prefix(n+1);
for (int j = 1; j <= n; j++)
prefix[j] = prefix[j-1] + grid[i-1][j-1];
for (int j = 1; j <= n; j++)
b_l[j] = max({b_l[j-1], dp[i-2][j-1][0], dp[i-2][j-1][1]});
b_h[n] = max(dp[i-2][n][0], dp[i-2][n][1]) + prefix[n];
for (int j = n-1; j >= 0; j--)
b_h[j] = max(b_h[j+1], max(dp[i-2][j][0], dp[i-2][j][1]) + prefix[j]);
for (int j = 1; j <= n; j++)
dp[i][j][0] = grid[i-1][j-1] + max({dp[i][j-1][0], dp[i-1][j-1][0]});
dp[i][n][1] = dp[i-1][n][1];
for (int j = n-1; j >= 0; j--)
dp[i][j][1] = max({dp[i][j+1][1], dp[i-1][j+1][1], dp[i-1][j+1][0]}) + grid[i][j];
for (int j = 0; j <= n; j++)
{
dp[i][j][0] = max({dp[i][j][0], b_l[j] + prefix[j], b_h[j]});
dp[i][j][1] = max({dp[i][j][1], b_l[j] + prefix[j], b_h[j]});
}
}
vector<int> prefix(n+1);
for (int i = 1; i <= n; i++)
prefix[i] = prefix[i-1] + grid[n-1][i-1];
int best = 0;
for (int i = 0; i <= n; i++)
best = max(best, dp[n-1][i][0]);
for (int i = 0; i <= n; i++)
best = max(best, max(dp[n-2][i][1], dp[n-2][i][0]) + prefix[i]);
return best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
501 ms |
290124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Runtime error |
546 ms |
294024 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
451 ms |
286288 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
240 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
2152 KB |
Output is correct |
10 |
Correct |
7 ms |
4820 KB |
Output is correct |
11 |
Correct |
3 ms |
2004 KB |
Output is correct |
12 |
Correct |
7 ms |
4820 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
5 ms |
4864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
240 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
2152 KB |
Output is correct |
10 |
Correct |
7 ms |
4820 KB |
Output is correct |
11 |
Correct |
3 ms |
2004 KB |
Output is correct |
12 |
Correct |
7 ms |
4820 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
5 ms |
4864 KB |
Output is correct |
15 |
Correct |
6 ms |
4820 KB |
Output is correct |
16 |
Correct |
2 ms |
980 KB |
Output is correct |
17 |
Correct |
19 ms |
5844 KB |
Output is correct |
18 |
Correct |
21 ms |
5836 KB |
Output is correct |
19 |
Correct |
25 ms |
5840 KB |
Output is correct |
20 |
Correct |
26 ms |
5868 KB |
Output is correct |
21 |
Correct |
18 ms |
5856 KB |
Output is correct |
22 |
Correct |
34 ms |
7000 KB |
Output is correct |
23 |
Correct |
10 ms |
5020 KB |
Output is correct |
24 |
Correct |
15 ms |
5460 KB |
Output is correct |
25 |
Correct |
5 ms |
4820 KB |
Output is correct |
26 |
Correct |
8 ms |
4972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
240 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
2152 KB |
Output is correct |
10 |
Correct |
7 ms |
4820 KB |
Output is correct |
11 |
Correct |
3 ms |
2004 KB |
Output is correct |
12 |
Correct |
7 ms |
4820 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
5 ms |
4864 KB |
Output is correct |
15 |
Correct |
6 ms |
4820 KB |
Output is correct |
16 |
Correct |
2 ms |
980 KB |
Output is correct |
17 |
Correct |
19 ms |
5844 KB |
Output is correct |
18 |
Correct |
21 ms |
5836 KB |
Output is correct |
19 |
Correct |
25 ms |
5840 KB |
Output is correct |
20 |
Correct |
26 ms |
5868 KB |
Output is correct |
21 |
Correct |
18 ms |
5856 KB |
Output is correct |
22 |
Correct |
34 ms |
7000 KB |
Output is correct |
23 |
Correct |
10 ms |
5020 KB |
Output is correct |
24 |
Correct |
15 ms |
5460 KB |
Output is correct |
25 |
Correct |
5 ms |
4820 KB |
Output is correct |
26 |
Correct |
8 ms |
4972 KB |
Output is correct |
27 |
Correct |
339 ms |
211888 KB |
Output is correct |
28 |
Correct |
111 ms |
28440 KB |
Output is correct |
29 |
Correct |
445 ms |
224436 KB |
Output is correct |
30 |
Correct |
455 ms |
224484 KB |
Output is correct |
31 |
Correct |
499 ms |
224492 KB |
Output is correct |
32 |
Correct |
126 ms |
23884 KB |
Output is correct |
33 |
Correct |
486 ms |
224496 KB |
Output is correct |
34 |
Correct |
463 ms |
224504 KB |
Output is correct |
35 |
Correct |
393 ms |
216660 KB |
Output is correct |
36 |
Correct |
450 ms |
224420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
451 ms |
286288 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
501 ms |
290124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |