#include <bits/stdc++.h>
//#include "fish.h"
using namespace std;
#define pb push_back
#define mp make_pair
long long dp[3005][3005][2]; //col,height,increasing/decreasing
long long pre[3005][3005];
long long max_weights(int n,int m,vector<int> x,vector<int> y,vector<int> w){
for (int i=0;i<m;i++){
x[i]++;
y[i]++;
pre[x[i]][y[i]]=w[i];
}
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
pre[i][j]+=pre[i][j-1];
}
}
for (int i=1;i<=n;i++){ //col
for (int j=0;j<=n;j++){ //col height
dp[i][j][0]=-1e18;
dp[i][j][1]=-1e18;
}
long long maxi=0;
for (int j=0;j<=n;j++){
maxi=max(maxi,dp[i-1][j][0]-pre[i][j]-pre[i-1][j]);
if (i>=2){
maxi=max(maxi,dp[i-2][j][1]-pre[i-1][j]);
}
dp[i][j][0]=maxi+pre[i-1][j]+pre[i+1][j];
}
maxi=0;
if (i>=2){
for (int j=n;j>=0;j--){
maxi=max(maxi,dp[i-2][j][1]);
dp[i][j][0]=max(dp[i][j][0],maxi+pre[i+1][j]);
}
}
maxi=0;
for (int j=n;j>=0;j--){
maxi=max(maxi,dp[i-1][j][1]);
dp[i][j][1]=maxi+pre[i+1][j]-pre[i][j];
}
/*
for (int j=0;j<=n;j++){
for (int k=j;k<=n;k++){
dp[i][j][1]=max(dp[i][j][1],dp[i-1][k][1]);
}
dp[i][j][1]+=pre[i+1][j]-pre[i][j];
}
*/
for (int j=0;j<=n;j++){
dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]);
}
}
long long ans=0;
for (int j=0;j<=n;j++){
ans=max(ans,dp[n][j][1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
118624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
1105 ms |
116728 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1099 ms |
108140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
4860 KB |
Output is correct |
11 |
Correct |
1 ms |
2004 KB |
Output is correct |
12 |
Correct |
5 ms |
4820 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
4860 KB |
Output is correct |
11 |
Correct |
1 ms |
2004 KB |
Output is correct |
12 |
Correct |
5 ms |
4820 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4820 KB |
Output is correct |
15 |
Correct |
3 ms |
4820 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
17 ms |
5844 KB |
Output is correct |
18 |
Correct |
19 ms |
5848 KB |
Output is correct |
19 |
Correct |
15 ms |
5872 KB |
Output is correct |
20 |
Correct |
19 ms |
5840 KB |
Output is correct |
21 |
Correct |
16 ms |
5844 KB |
Output is correct |
22 |
Correct |
26 ms |
6868 KB |
Output is correct |
23 |
Correct |
5 ms |
5076 KB |
Output is correct |
24 |
Correct |
10 ms |
5460 KB |
Output is correct |
25 |
Correct |
3 ms |
4820 KB |
Output is correct |
26 |
Correct |
5 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
4860 KB |
Output is correct |
11 |
Correct |
1 ms |
2004 KB |
Output is correct |
12 |
Correct |
5 ms |
4820 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4820 KB |
Output is correct |
15 |
Correct |
3 ms |
4820 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
17 ms |
5844 KB |
Output is correct |
18 |
Correct |
19 ms |
5848 KB |
Output is correct |
19 |
Correct |
15 ms |
5872 KB |
Output is correct |
20 |
Correct |
19 ms |
5840 KB |
Output is correct |
21 |
Correct |
16 ms |
5844 KB |
Output is correct |
22 |
Correct |
26 ms |
6868 KB |
Output is correct |
23 |
Correct |
5 ms |
5076 KB |
Output is correct |
24 |
Correct |
10 ms |
5460 KB |
Output is correct |
25 |
Correct |
3 ms |
4820 KB |
Output is correct |
26 |
Correct |
5 ms |
4948 KB |
Output is correct |
27 |
Correct |
150 ms |
211964 KB |
Output is correct |
28 |
Correct |
78 ms |
24864 KB |
Output is correct |
29 |
Correct |
248 ms |
219384 KB |
Output is correct |
30 |
Correct |
265 ms |
219248 KB |
Output is correct |
31 |
Correct |
277 ms |
219356 KB |
Output is correct |
32 |
Correct |
110 ms |
19088 KB |
Output is correct |
33 |
Correct |
267 ms |
219252 KB |
Output is correct |
34 |
Correct |
266 ms |
219340 KB |
Output is correct |
35 |
Correct |
187 ms |
214880 KB |
Output is correct |
36 |
Correct |
259 ms |
219204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1099 ms |
108140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
118624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |