#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int N, int M,vector<int> X,vector<int> Y,
vector<int> W){
vector DP(N+1,vector(N+1,vector(2,0ll)));
vector pref(N+2,vector(N+1,0ll));
vector transition1(N+1,vector(N+1,0ll));
vector transition2(N+1,vector(N+1,0ll));
vector transition3(N+1,vector(N+1,0ll));
vector transition4(N+1,vector(N+1,0ll));
for(int i=0;i<M;i++) {
pref[X[i]+1][Y[i]+1]=W[i];
}
for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)pref[i][j]+=pref[i][j-1];
for(int i=2;i<=N;i++) {
for(int j=0;j<=N;j++) {
if(i!=2)DP[i][j][1]=max(DP[i][j][1],-pref[i][j]+transition1[i-1][j]);
else {
for(int x=j;x<=N;x++) {
DP[i][j][1]=max(DP[i][j][1],pref[i][x]-pref[i][j]+max(DP[i-1][x][0],DP[i-1][x][1]));
}
}
if(i>2) {
for(int x=0;x<=N;x++) {
DP[i][j][0]=max(DP[i][j][0],pref[i-1][max(x,j)]+max(DP[i-2][x][0],DP[i-2][x][1]));
}
}
if(i!=2)DP[i][j][0]=max(DP[i][j][0],pref[i-1][j]+transition4[i-1][j]);
else for(int x=0;x<=j;x++) {
DP[i][j][0]=max(DP[i][j][0],pref[i-1][j]-pref[i-1][x]+DP[i-1][x][0]);
}
transition1[i][j]=pref[i+1][j]+max(DP[i][j][0],DP[i][j][1]);
transition4[i][j]=-pref[i][j]+DP[i][j][0];
}
for(int j=N-1;j>=0;j--)transition1[i][j]=max(transition1[i][j],transition1[i][j+1]);
for(int j=1;j<=N;j++)transition4[i][j]=max(transition4[i][j],transition4[i][j-1]);
}
long long ans = 0;
for(int j=0;j<=N;j++)ans=max(ans,DP[N][j][0]);
for(int j=0;j<=N;j++)ans=max(ans,DP[N][j][1]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1101 ms |
1770320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1162 ms |
1866324 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
1299032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
504 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 |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
2396 KB |
Output is correct |
10 |
Correct |
38 ms |
9024 KB |
Output is correct |
11 |
Correct |
6 ms |
2396 KB |
Output is correct |
12 |
Correct |
40 ms |
8792 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
38 ms |
8872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
504 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 |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
2396 KB |
Output is correct |
10 |
Correct |
38 ms |
9024 KB |
Output is correct |
11 |
Correct |
6 ms |
2396 KB |
Output is correct |
12 |
Correct |
40 ms |
8792 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
38 ms |
8872 KB |
Output is correct |
15 |
Correct |
37 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
856 KB |
Output is correct |
17 |
Correct |
45 ms |
10076 KB |
Output is correct |
18 |
Correct |
47 ms |
10052 KB |
Output is correct |
19 |
Correct |
51 ms |
10052 KB |
Output is correct |
20 |
Correct |
44 ms |
10072 KB |
Output is correct |
21 |
Correct |
44 ms |
10076 KB |
Output is correct |
22 |
Correct |
52 ms |
10976 KB |
Output is correct |
23 |
Correct |
39 ms |
9052 KB |
Output is correct |
24 |
Correct |
42 ms |
9564 KB |
Output is correct |
25 |
Correct |
37 ms |
8792 KB |
Output is correct |
26 |
Correct |
42 ms |
9048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
504 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 |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
2396 KB |
Output is correct |
10 |
Correct |
38 ms |
9024 KB |
Output is correct |
11 |
Correct |
6 ms |
2396 KB |
Output is correct |
12 |
Correct |
40 ms |
8792 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
38 ms |
8872 KB |
Output is correct |
15 |
Correct |
37 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
856 KB |
Output is correct |
17 |
Correct |
45 ms |
10076 KB |
Output is correct |
18 |
Correct |
47 ms |
10052 KB |
Output is correct |
19 |
Correct |
51 ms |
10052 KB |
Output is correct |
20 |
Correct |
44 ms |
10072 KB |
Output is correct |
21 |
Correct |
44 ms |
10076 KB |
Output is correct |
22 |
Correct |
52 ms |
10976 KB |
Output is correct |
23 |
Correct |
39 ms |
9052 KB |
Output is correct |
24 |
Correct |
42 ms |
9564 KB |
Output is correct |
25 |
Correct |
37 ms |
8792 KB |
Output is correct |
26 |
Correct |
42 ms |
9048 KB |
Output is correct |
27 |
Execution timed out |
1111 ms |
846932 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
1299032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1101 ms |
1770320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |