#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];
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
n = N;
for(int i = 0; i < M; i++){
X[i]++; Y[i]++;
a[X[i]][Y[i]] += W[i];
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
a[i][j] += a[i][j-1];
}
}
for(int i = 2; i <= n; i++){
for(int j = 0; j <= n; j++){
dp[i][j][0] = dp[i][j][1] = -1e18;
}
}
for(int i = 1; i < n; i++){
for(int j = 0; j <= n; j++){
for(int k = 0; k <= n; k++){
if(k >= j) dp[i+1][k][1] = max(dp[i+1][k][1], dp[i][j][1] + a[i][k] - a[i][j]);
if(k <= j) dp[i+1][k][0] = max(dp[i+1][k][0], max(dp[i][j][1], dp[i][j][0]) + a[i+1][j] - a[i+1][k]);
if(i > 1){
dp[i+1][k][0] = max(dp[i+1][k][0], max(dp[i-1][j][1], dp[i-1][j][0]) + a[i][max(j, k)]);
dp[i+1][k][1] = max(dp[i+1][k][1], max(dp[i-1][j][1], dp[i-1][j][0]) + a[i][max(j, k)]);
}
}
}
}
ll res = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int c = 0; c < 2; c++){
res = max(res, dp[i][j][c]);
}
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
642 ms |
461780 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
666 ms |
465748 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
716 ms |
457824 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2468 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
19 ms |
14684 KB |
Output is correct |
10 |
Correct |
89 ms |
25156 KB |
Output is correct |
11 |
Correct |
11 ms |
14684 KB |
Output is correct |
12 |
Correct |
76 ms |
24924 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
86 ms |
25144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2468 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
19 ms |
14684 KB |
Output is correct |
10 |
Correct |
89 ms |
25156 KB |
Output is correct |
11 |
Correct |
11 ms |
14684 KB |
Output is correct |
12 |
Correct |
76 ms |
24924 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
86 ms |
25144 KB |
Output is correct |
15 |
Correct |
76 ms |
24924 KB |
Output is correct |
16 |
Correct |
4 ms |
8540 KB |
Output is correct |
17 |
Correct |
92 ms |
26972 KB |
Output is correct |
18 |
Correct |
119 ms |
26712 KB |
Output is correct |
19 |
Correct |
83 ms |
26712 KB |
Output is correct |
20 |
Correct |
117 ms |
26964 KB |
Output is correct |
21 |
Correct |
85 ms |
26712 KB |
Output is correct |
22 |
Correct |
124 ms |
28496 KB |
Output is correct |
23 |
Correct |
81 ms |
25472 KB |
Output is correct |
24 |
Correct |
80 ms |
26204 KB |
Output is correct |
25 |
Correct |
77 ms |
24924 KB |
Output is correct |
26 |
Correct |
77 ms |
25432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2468 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
19 ms |
14684 KB |
Output is correct |
10 |
Correct |
89 ms |
25156 KB |
Output is correct |
11 |
Correct |
11 ms |
14684 KB |
Output is correct |
12 |
Correct |
76 ms |
24924 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
86 ms |
25144 KB |
Output is correct |
15 |
Correct |
76 ms |
24924 KB |
Output is correct |
16 |
Correct |
4 ms |
8540 KB |
Output is correct |
17 |
Correct |
92 ms |
26972 KB |
Output is correct |
18 |
Correct |
119 ms |
26712 KB |
Output is correct |
19 |
Correct |
83 ms |
26712 KB |
Output is correct |
20 |
Correct |
117 ms |
26964 KB |
Output is correct |
21 |
Correct |
85 ms |
26712 KB |
Output is correct |
22 |
Correct |
124 ms |
28496 KB |
Output is correct |
23 |
Correct |
81 ms |
25472 KB |
Output is correct |
24 |
Correct |
80 ms |
26204 KB |
Output is correct |
25 |
Correct |
77 ms |
24924 KB |
Output is correct |
26 |
Correct |
77 ms |
25432 KB |
Output is correct |
27 |
Execution timed out |
1018 ms |
222296 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
716 ms |
457824 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
642 ms |
461780 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |