#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int pref[3005][3005];
int query(int j, int i1, int i2) {
if (i1 > i2) {
return 0;
}
return pref[i2][j]-pref[i1-1][j];
}
int max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
int n = N, m = M, yn;
yn = N;
vector<vector<int>> c(yn+1, vector<int>(n+1, 0));
vector<vector<vector<int>>> dp(yn+1, vector<vector<int>>(n+1, vector<int>(2, 0))); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
for (int i = 0; i < m; i++) {
c[Y[i]+1][X[i]] = W[i];
pref[Y[i]+1][X[i]] = W[i];
}
for (int j = 0; j < n; j++) {
for (int i = 1; i <= yn; i++) {
pref[i][j] += pref[i-1][j];
}
}
for (int j = 1; j < n; j++) {
int v = 0;
dp[0][j][0] = max(dp[0][j][0], dp[0][j-1][0]);
for (int i = 1; i <= yn; i++) {
v += c[i][j];
dp[0][j][0] = max(dp[0][j][0], dp[i][j-1][0]+v);
dp[0][j][0] = max(dp[0][j][0], dp[i][j-1][1]+v);
}
for (int i = 1; i <= yn; i++) {
for (int a = i; a <= yn; a++) {
v = query(j, i+1, a);
dp[i][j][1] = max(dp[i][j][1], dp[a][j-1][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[a][j-1][1]+v);
}
for (int a = 1; a <= i; a++) {
v = query(j-1, a+1, i);
dp[i][j][0] = max(dp[i][j][0], dp[a][j-1][0]+v);
}
}
if (j == 1) {
v = 0;
for (int i = 1; i <= yn; i++) {
v += c[i][j-1];
dp[i][j][0] = max(dp[i][j][0], dp[0][j-1][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[0][j-1][0]+v);
}
}
if (j-2 >= 0) {
v = 0;
for (int i = 1; i <= yn; i++) {
v += c[i][j-1];
dp[i][j][0] = max(dp[i][j][0], dp[0][j-2][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[0][j-2][0]+v);
}
for (int i = 1; i <= yn; i++) {
v = 0;
for (int h = 1; h <= i; h++) {
v += c[h][j-1];
}
for (int h = 1; h <= i; h++) {
dp[i][j][0] = max(dp[i][j][0], dp[h][j-2][0]+v); // we just max of j-2 opt
dp[i][j][0] = max(dp[i][j][0], dp[h][j-2][1]+v);
dp[i][j][1] = max(dp[i][j][1], dp[h][j-2][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[h][j-2][1]+v);
}
}
}
}
int ans = 0;
for (int i = 0; i <= yn; i++) {
ans = max(ans, dp[i][n-1][0]);
ans = max(ans, dp[i][n-1][1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
865 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
863 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
825 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
21 ms |
2696 KB |
Output is correct |
10 |
Correct |
144 ms |
8028 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
155 ms |
8084 KB |
Output is correct |
13 |
Correct |
3 ms |
1112 KB |
Output is correct |
14 |
Correct |
143 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
21 ms |
2696 KB |
Output is correct |
10 |
Correct |
144 ms |
8028 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
155 ms |
8084 KB |
Output is correct |
13 |
Correct |
3 ms |
1112 KB |
Output is correct |
14 |
Correct |
143 ms |
8028 KB |
Output is correct |
15 |
Correct |
143 ms |
8040 KB |
Output is correct |
16 |
Correct |
3 ms |
1112 KB |
Output is correct |
17 |
Correct |
158 ms |
9684 KB |
Output is correct |
18 |
Correct |
151 ms |
9816 KB |
Output is correct |
19 |
Correct |
148 ms |
9820 KB |
Output is correct |
20 |
Correct |
153 ms |
9816 KB |
Output is correct |
21 |
Correct |
157 ms |
9820 KB |
Output is correct |
22 |
Correct |
159 ms |
11604 KB |
Output is correct |
23 |
Correct |
142 ms |
8280 KB |
Output is correct |
24 |
Correct |
158 ms |
9236 KB |
Output is correct |
25 |
Correct |
145 ms |
8028 KB |
Output is correct |
26 |
Correct |
142 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
21 ms |
2696 KB |
Output is correct |
10 |
Correct |
144 ms |
8028 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
155 ms |
8084 KB |
Output is correct |
13 |
Correct |
3 ms |
1112 KB |
Output is correct |
14 |
Correct |
143 ms |
8028 KB |
Output is correct |
15 |
Correct |
143 ms |
8040 KB |
Output is correct |
16 |
Correct |
3 ms |
1112 KB |
Output is correct |
17 |
Correct |
158 ms |
9684 KB |
Output is correct |
18 |
Correct |
151 ms |
9816 KB |
Output is correct |
19 |
Correct |
148 ms |
9820 KB |
Output is correct |
20 |
Correct |
153 ms |
9816 KB |
Output is correct |
21 |
Correct |
157 ms |
9820 KB |
Output is correct |
22 |
Correct |
159 ms |
11604 KB |
Output is correct |
23 |
Correct |
142 ms |
8280 KB |
Output is correct |
24 |
Correct |
158 ms |
9236 KB |
Output is correct |
25 |
Correct |
145 ms |
8028 KB |
Output is correct |
26 |
Correct |
142 ms |
8280 KB |
Output is correct |
27 |
Execution timed out |
1092 ms |
635472 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
825 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
865 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |