#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
ll dp[3005][3005][3]; // A(a), (A)a, (A)
int pos[3005][3005];
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
for(int i=0;i<sz(x);i++) pos[x[i]+1][y[i]+1] = w[i];
memset(dp, -1, sizeof(dp));
ll ans = 0;
for(int i=1;i<=n;i++){
ll pref[3][3005];
ll suff[3005];
memset(suff, 0, sizeof(suff));
memset(pref, 0, sizeof(pref));
for(int j=1;j<=n;j++){
pref[0][j] = pref[0][j-1] + pos[i-1][j];
pref[1][j] = pref[1][j-1] + pos[i][j];
pref[2][j] = pref[2][j-1] + pos[i+1][j];
}
for(int j=n;j>=1;j--){
suff[j] = max(suff[j+1], dp[i-1][j][0]);
}
if(i == 1){
for(int j=0;j<=n;j++) dp[i][j][2] = 0;
}
else{
// 0
ll mx = -1e18;
for(int j=n;j>=0;j--){
if(dp[i-1][j][0] != -1) mx = max(mx, dp[i-1][j][0] + pref[1][j]);
dp[i][j][0] = max(dp[i][j][0], mx - pref[1][j]);
}
// 1
mx = 1e18;
for(int j=n;j>=0;j--){
dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][0] + pref[1][j]);
dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][2] + pref[1][j]);
}
// 2
ll mx0 = -1e18, mx1 = -1e18, mx2 = -1e18;
for(int j=0;j<=n;j++){
if(dp[i-1][j][0] != -1) mx0 = max(mx0, dp[i-1][j][0]);
if(dp[i-1][j][1] != -1) mx1 = max(mx1, dp[i-1][j][1] - pref[0][j]);
if(dp[i-1][j][2] != -1) mx2 = max(mx2, dp[i-1][j][2] - pref[0][j]);
dp[i][j][2] = max(dp[i][j][2], mx0);
dp[i][j][2] = max(dp[i][j][2], mx1 + pref[0][j]);
dp[i][j][2] = max(dp[i][j][2], mx2 + pref[0][j]);
}
}
ll sum = 0;
for(int j=0;j<=n;j++){
sum += pos[i+1][j];
ans = max(ans, dp[i][j][0] + sum);
ans = max(ans, dp[i][j][2] + sum);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
269 ms |
436460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
212336 KB |
Output is correct |
2 |
Runtime error |
298 ms |
441780 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
250 ms |
430624 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
212352 KB |
Output is correct |
2 |
Correct |
79 ms |
212364 KB |
Output is correct |
3 |
Correct |
78 ms |
212436 KB |
Output is correct |
4 |
Correct |
81 ms |
212428 KB |
Output is correct |
5 |
Correct |
80 ms |
212428 KB |
Output is correct |
6 |
Correct |
77 ms |
212372 KB |
Output is correct |
7 |
Correct |
78 ms |
212316 KB |
Output is correct |
8 |
Incorrect |
78 ms |
212428 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
212352 KB |
Output is correct |
2 |
Correct |
79 ms |
212364 KB |
Output is correct |
3 |
Correct |
78 ms |
212436 KB |
Output is correct |
4 |
Correct |
81 ms |
212428 KB |
Output is correct |
5 |
Correct |
80 ms |
212428 KB |
Output is correct |
6 |
Correct |
77 ms |
212372 KB |
Output is correct |
7 |
Correct |
78 ms |
212316 KB |
Output is correct |
8 |
Incorrect |
78 ms |
212428 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
212352 KB |
Output is correct |
2 |
Correct |
79 ms |
212364 KB |
Output is correct |
3 |
Correct |
78 ms |
212436 KB |
Output is correct |
4 |
Correct |
81 ms |
212428 KB |
Output is correct |
5 |
Correct |
80 ms |
212428 KB |
Output is correct |
6 |
Correct |
77 ms |
212372 KB |
Output is correct |
7 |
Correct |
78 ms |
212316 KB |
Output is correct |
8 |
Incorrect |
78 ms |
212428 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
250 ms |
430624 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
269 ms |
436460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |