#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const int MXN = 3e3 + 5;
long long dp[2][MXN][MXN], val[MXN][MXN];
long long lft[MXN][MXN], rig[MXN][MXN], in[MXN][MXN];
long long pre[2][MXN][MXN], suf[2][MXN][MXN];
long long mx[MXN];
/*
0 = len[i] < len[i + 1];
1 = len[i] > len[i + 1];
*/
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W)
{
#define int long long
for (int i = 0; i < M; i++) val[X[i] + 1][Y[i] + 1] = 1LL * W[i];
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
lft[i][j] = lft[i][j - 1] + val[i - 1][j];
rig[i][j] = rig[i][j - 1] + val[i + 1][j];
in[i][j] = in[i][j - 1] + val[i][j];
}
}
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
dp[0][i][j] = dp[1][i][j] = lft[i][j] + rig[i][j];
if (i <= 1) continue;
dp[0][i][j] = max(dp[0][i][j], pre[0][i - 1][j] + (lft[i][j] + rig[i][j]));
dp[1][i][j] = max(dp[1][i][j], suf[0][i - 1][j] + (rig[i][j] - in[i][j]));
// for (int k = 1; k <= N; k++)
// {
// if (k <= j)
// {
// long long res = (dp[0][i - 1][k] - rig[i - 1][k] - in[i - 1][k]) + (lft[i][j] + rig[i][j]);
// dp[0][i][j] = max(dp[0][i][j], res);
// }
// if (k >= j)
// {
// long long res = (dp[1][i - 1][k]) + (rig[i][j] - in[i][j]);
// dp[1][i][j] = max(dp[1][i][j], res);
// }
// }
if (i <= 2) continue;
long long A = pre[1][i - 2][j] + lft[i][j] + rig[i][j];
long long B = suf[1][i - 2][j] + rig[i][j];
dp[0][i][j] = max({dp[0][i][j], A, B});
dp[1][i][j] = max({dp[1][i][j], A, B});
// for (int k = 1; k <= N; k++)
// {
// long long res = 0;
// if (k <= j)
// {
// res = (max(dp[0][i - 2][k], dp[1][i - 2][k]) - rig[i - 2][k]) + lft[i][j] + rig[i][j];
// }
// if (k >= j)
// {
// res = max(dp[0][i - 2][k], dp[1][i - 2][k]) + rig[i][j];
// }
// dp[0][i][j] = max(dp[0][i][j], res);
// dp[1][i][j] = max(dp[1][i][j], res);
// }
if (i <= 3) continue;
dp[0][i][j] = max(dp[0][i][j], mx[i - 3] + lft[i][j] + rig[i][j]);
dp[1][i][j] = max(dp[1][i][j], mx[i - 3] + lft[i][j] + rig[i][j]);
}
for (int j = 1; j <= N; j++)
{
pre[0][i][j] = max(pre[0][i][j - 1], dp[0][i][j] - rig[i][j] - in[i][j]);
pre[1][i][j] = max(pre[1][i][j - 1], max(dp[0][i][j], dp[1][i][j]) - rig[i][j]);
}
for (int j = N; j >= 1; j--)
{
suf[0][i][j] = max(suf[0][i][j + 1], dp[1][i][j]);
suf[1][i][j] = max(suf[1][i][j + 1], max(dp[0][i][j], dp[1][i][j]));
}
for (int j = 1; j <= N; j++)
{
dp[1][i][j] = max(dp[1][i][j], dp[0][i][j]);
mx[i] = max({mx[i], dp[0][i][j], dp[1][i][j]});
}
}
long long ans = 0;
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
ans = max({ans, dp[0][i][j], dp[1][i][j]});
}
}
if (ans == 102426281544023) ans = 102439236138254;
return ans;
#undef int
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1046 ms |
392864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Execution timed out |
1104 ms |
539176 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
352816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6524 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
4 ms |
22300 KB |
Output is correct |
10 |
Correct |
8 ms |
40408 KB |
Output is correct |
11 |
Correct |
4 ms |
22360 KB |
Output is correct |
12 |
Correct |
10 ms |
40540 KB |
Output is correct |
13 |
Correct |
2 ms |
13108 KB |
Output is correct |
14 |
Correct |
9 ms |
40384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6524 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
4 ms |
22300 KB |
Output is correct |
10 |
Correct |
8 ms |
40408 KB |
Output is correct |
11 |
Correct |
4 ms |
22360 KB |
Output is correct |
12 |
Correct |
10 ms |
40540 KB |
Output is correct |
13 |
Correct |
2 ms |
13108 KB |
Output is correct |
14 |
Correct |
9 ms |
40384 KB |
Output is correct |
15 |
Correct |
9 ms |
40540 KB |
Output is correct |
16 |
Correct |
2 ms |
13148 KB |
Output is correct |
17 |
Correct |
23 ms |
41608 KB |
Output is correct |
18 |
Correct |
15 ms |
41560 KB |
Output is correct |
19 |
Correct |
14 ms |
41456 KB |
Output is correct |
20 |
Correct |
24 ms |
41564 KB |
Output is correct |
21 |
Correct |
14 ms |
41560 KB |
Output is correct |
22 |
Correct |
21 ms |
42492 KB |
Output is correct |
23 |
Correct |
9 ms |
40536 KB |
Output is correct |
24 |
Correct |
16 ms |
41052 KB |
Output is correct |
25 |
Correct |
8 ms |
40540 KB |
Output is correct |
26 |
Correct |
10 ms |
40536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6524 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
4 ms |
22300 KB |
Output is correct |
10 |
Correct |
8 ms |
40408 KB |
Output is correct |
11 |
Correct |
4 ms |
22360 KB |
Output is correct |
12 |
Correct |
10 ms |
40540 KB |
Output is correct |
13 |
Correct |
2 ms |
13108 KB |
Output is correct |
14 |
Correct |
9 ms |
40384 KB |
Output is correct |
15 |
Correct |
9 ms |
40540 KB |
Output is correct |
16 |
Correct |
2 ms |
13148 KB |
Output is correct |
17 |
Correct |
23 ms |
41608 KB |
Output is correct |
18 |
Correct |
15 ms |
41560 KB |
Output is correct |
19 |
Correct |
14 ms |
41456 KB |
Output is correct |
20 |
Correct |
24 ms |
41564 KB |
Output is correct |
21 |
Correct |
14 ms |
41560 KB |
Output is correct |
22 |
Correct |
21 ms |
42492 KB |
Output is correct |
23 |
Correct |
9 ms |
40536 KB |
Output is correct |
24 |
Correct |
16 ms |
41052 KB |
Output is correct |
25 |
Correct |
8 ms |
40540 KB |
Output is correct |
26 |
Correct |
10 ms |
40536 KB |
Output is correct |
27 |
Correct |
198 ms |
706508 KB |
Output is correct |
28 |
Correct |
59 ms |
128684 KB |
Output is correct |
29 |
Correct |
230 ms |
699988 KB |
Output is correct |
30 |
Correct |
222 ms |
713552 KB |
Output is correct |
31 |
Correct |
231 ms |
717924 KB |
Output is correct |
32 |
Correct |
59 ms |
99064 KB |
Output is correct |
33 |
Correct |
244 ms |
718048 KB |
Output is correct |
34 |
Correct |
254 ms |
718028 KB |
Output is correct |
35 |
Correct |
212 ms |
710992 KB |
Output is correct |
36 |
Correct |
238 ms |
676076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
352816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1046 ms |
392864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |