#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e3 + 100;
const int maxl = 11;
int n;
ll dp[maxn][maxn][2];
ll a[maxn][maxn];
ll pref[2][100100];
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
n = N;
if(*max_element(X.begin(), X.end()) <= 1 && n > 2){
for(int i = 0; i < M; i++){
Y[i]++;
pref[X[i]][Y[i]] += W[i];
}
for(int i = 1; i <= n; i++){
pref[0][i] += pref[0][i-1];
}
for(int i = n; i > 0; i--){
pref[1][i] += pref[1][i+1];
}
ll ans = 0;
for(int i = 0; i <= n; i++){
ans = max(ans, pref[0][i] + pref[1][i+1]);
}
return ans;
}
bool ok = 1;
ll sum = 0;
for(int i = 0; i < M; i++){
X[i]++; Y[i]++;
if(Y[i] <= 11){
a[X[i]][Y[i]] += W[i];
}
ok &= X[i] & 1;
sum += W[i];
}
if(ok) return sum;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
a[i][j] += a[i][j-1];
}
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= n; j++){
dp[i][j][0] = dp[i][j][1] = -(ll)1e18;
if(i == 1) dp[i][j][1] = 0;
}
}
for(int i = 1; i < n; i++){
for(int j = 0; j <= n; j++){
for(int k = 0; k <= n; k++){
if(j <= k){
dp[i+1][k][1] = max(dp[i+1][k][1], dp[i][j][1] + a[i][k] - a[i][j]);
}
if(j >= k){
dp[i+1][k][0] = max(dp[i+1][k][0], dp[i][j][0] + a[i+1][j] - a[i+1][k]);
}
if(i + 2 <= n){
dp[i+2][k][0] = max(dp[i+2][k][0], dp[i][j][1] + a[i][n] + a[i+2][k] - a[i][j] - a[i+2][k]);
dp[i+2][k][1] = max(dp[i+2][k][1], dp[i][j][0] + a[i+1][min(i, k)]);
}
}
}
}
ll ans = 0;
for(int i = 0; i <= n; i++){
for(int c = 0; c < 2; c++){
ans = max(ans, dp[n][i][c]);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
5204 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Correct |
1 ms |
2140 KB |
Output is correct |
5 |
Runtime error |
67 ms |
18056 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
5428 KB |
Output is correct |
3 |
Correct |
37 ms |
10072 KB |
Output is correct |
4 |
Correct |
15 ms |
4972 KB |
Output is correct |
5 |
Correct |
19 ms |
5980 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Runtime error |
3 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Runtime error |
3 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
5204 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Correct |
1 ms |
2140 KB |
Output is correct |
5 |
Runtime error |
67 ms |
18056 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |