#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
#include "fish.h"
ll arr[3005][3005],prearr[3005][3005];
ll dp[3005][3005],dp2[3005][3005]; // dp2 if adjacent AND lower
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
for(int i=0;i<m;i++){
arr[x[i]+1][y[i]+1] = w[i];
}
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
prearr[i][j] = prearr[i][j-1]+arr[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
// if first port
dp[i][j] = prearr[i-1][j]+prearr[i+1][j];
if(i-1<=0){
continue;
}
for(int k=0;k<=n;k++){
// build port at x=i, height = j, connects to port at x=i-1, height = k
if(j>k){
dp[i][j] = max(dp[i][j],dp[i-1][k]-prearr[i][k]+prearr[i+1][j]+prearr[i-1][j]-prearr[i-1][k]);
}
else if(j==k){
dp[i][j] = max(dp[i][j],max(dp[i-1][k],dp2[i-1][k])-prearr[i][j]+prearr[i+1][j]);
}
else if(j<k){
dp2[i][j] = max(dp2[i][j],max(dp[i-1][k],dp2[i-1][k])-prearr[i][j]+prearr[i+1][j]);
}
}
if(i-2<=0){
continue;
}
for(int k=0;k<=n;k++){
// build port at x=i, height = j, connects to port at x=i-2, height = k
dp[i][j] = max(dp[i][j],dp[i-2][k]+prearr[i-1][j]+prearr[i+1][j]-2LL*prearr[i-1][min(j,k)]);
}
}
}
ll ans=0;
for(int i=0;i<=n;i++){
ans = max(ans,max(dp[n][i],dp2[n][i]));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
768 ms |
149124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Runtime error |
789 ms |
153104 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
822 ms |
143820 KB |
Execution killed with signal 11 |
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 |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
12 ms |
3284 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
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 |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
12 ms |
3284 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
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 |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
12 ms |
3284 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
822 ms |
143820 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
768 ms |
149124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |