#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
//calculate increasing
for (int k=0;k<=j;k++){ //prev col height
long long cur=dp[i-1][k][0];
cur-=pre[i][k];
cur+=pre[i-1][j]-pre[i-1][k];
cur+=pre[i+1][j];
dp[i][j][0]=max(dp[i][j][0],cur);
}
if (i>=2){
//i-1 is 0
for (int k=0;k<=j;k++){ //i-2 col height
long long cur=dp[i-2][k][1];
cur+=pre[i-1][j]-pre[i-1][k];
cur+=pre[i+1][j];
dp[i][j][0]=max(dp[i][j][0],cur);
}
for (int k=j;k<=n;k++){ //i-2 col height
long long cur=dp[i-2][k][1];
cur+=pre[i+1][j];
dp[i][j][0]=max(dp[i][j][0],cur);
}
}
//calculate decreasing
for (int k=j;k<=n;k++){ //prev col height
long long cur=max(dp[i-1][k][0],dp[i-1][k][1]);
cur-=pre[i][j];
cur+=pre[i+1][j];
dp[i][j][1]=max(dp[i][j][1],cur);
}
}
dp[i][0][0]=max(dp[i][0][0],dp[i-1][0][1]);
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 |
1091 ms |
119824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1082 ms |
117648 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
108496 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
9 ms |
2004 KB |
Output is correct |
10 |
Correct |
67 ms |
4780 KB |
Output is correct |
11 |
Correct |
9 ms |
2004 KB |
Output is correct |
12 |
Correct |
71 ms |
4844 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
68 ms |
4764 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
9 ms |
2004 KB |
Output is correct |
10 |
Correct |
67 ms |
4780 KB |
Output is correct |
11 |
Correct |
9 ms |
2004 KB |
Output is correct |
12 |
Correct |
71 ms |
4844 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
68 ms |
4764 KB |
Output is correct |
15 |
Correct |
73 ms |
4832 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
80 ms |
5804 KB |
Output is correct |
18 |
Correct |
77 ms |
5784 KB |
Output is correct |
19 |
Correct |
82 ms |
5836 KB |
Output is correct |
20 |
Correct |
79 ms |
5852 KB |
Output is correct |
21 |
Correct |
77 ms |
5812 KB |
Output is correct |
22 |
Correct |
92 ms |
6912 KB |
Output is correct |
23 |
Correct |
79 ms |
5000 KB |
Output is correct |
24 |
Correct |
78 ms |
5516 KB |
Output is correct |
25 |
Correct |
70 ms |
4852 KB |
Output is correct |
26 |
Correct |
68 ms |
4988 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
9 ms |
2004 KB |
Output is correct |
10 |
Correct |
67 ms |
4780 KB |
Output is correct |
11 |
Correct |
9 ms |
2004 KB |
Output is correct |
12 |
Correct |
71 ms |
4844 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
68 ms |
4764 KB |
Output is correct |
15 |
Correct |
73 ms |
4832 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
80 ms |
5804 KB |
Output is correct |
18 |
Correct |
77 ms |
5784 KB |
Output is correct |
19 |
Correct |
82 ms |
5836 KB |
Output is correct |
20 |
Correct |
79 ms |
5852 KB |
Output is correct |
21 |
Correct |
77 ms |
5812 KB |
Output is correct |
22 |
Correct |
92 ms |
6912 KB |
Output is correct |
23 |
Correct |
79 ms |
5000 KB |
Output is correct |
24 |
Correct |
78 ms |
5516 KB |
Output is correct |
25 |
Correct |
70 ms |
4852 KB |
Output is correct |
26 |
Correct |
68 ms |
4988 KB |
Output is correct |
27 |
Execution timed out |
1093 ms |
73176 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
108496 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
119824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |