#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;
vector<vector<int>> c(n+1, vector<int>(n+1, 0));
vector<vector<int>> dp(n+1, vector<int>(2, 0)), tdp(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 <= n; i++) {
pref[i][j] += pref[i-1][j];
}
}
for (int j = 1; j <= n; j++) {
int v = 0;
for (int i = 0; i <= n; i++) {
v = max(v, dp[i][0]-pref[i][j-1]);
tdp[i][0] = max(v+pref[i][j-1], dp[0][1]);
}
v = 0;
for (int i = n; i >= 0; i--) {
v= max(v, max(dp[i][0], dp[i][1])+pref[i][j]);
tdp[i][1] = v-pref[i][j];
}
swap(dp, tdp);
}
int ans = max(dp[0][0], dp[0][1]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
926 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
870 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
839 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
1220 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
1220 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
2908 KB |
Output is correct |
15 |
Correct |
2 ms |
3116 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
11 ms |
4956 KB |
Output is correct |
18 |
Correct |
10 ms |
4700 KB |
Output is correct |
19 |
Correct |
9 ms |
4700 KB |
Output is correct |
20 |
Correct |
10 ms |
4680 KB |
Output is correct |
21 |
Correct |
16 ms |
4700 KB |
Output is correct |
22 |
Correct |
17 ms |
6488 KB |
Output is correct |
23 |
Correct |
4 ms |
3420 KB |
Output is correct |
24 |
Correct |
8 ms |
4228 KB |
Output is correct |
25 |
Correct |
2 ms |
3160 KB |
Output is correct |
26 |
Correct |
3 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
1220 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
2908 KB |
Output is correct |
15 |
Correct |
2 ms |
3116 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
11 ms |
4956 KB |
Output is correct |
18 |
Correct |
10 ms |
4700 KB |
Output is correct |
19 |
Correct |
9 ms |
4700 KB |
Output is correct |
20 |
Correct |
10 ms |
4680 KB |
Output is correct |
21 |
Correct |
16 ms |
4700 KB |
Output is correct |
22 |
Correct |
17 ms |
6488 KB |
Output is correct |
23 |
Correct |
4 ms |
3420 KB |
Output is correct |
24 |
Correct |
8 ms |
4228 KB |
Output is correct |
25 |
Correct |
2 ms |
3160 KB |
Output is correct |
26 |
Correct |
3 ms |
3416 KB |
Output is correct |
27 |
Correct |
199 ms |
141908 KB |
Output is correct |
28 |
Correct |
47 ms |
21076 KB |
Output is correct |
29 |
Correct |
246 ms |
154448 KB |
Output is correct |
30 |
Correct |
258 ms |
154452 KB |
Output is correct |
31 |
Correct |
251 ms |
154452 KB |
Output is correct |
32 |
Correct |
56 ms |
19436 KB |
Output is correct |
33 |
Correct |
254 ms |
154608 KB |
Output is correct |
34 |
Correct |
267 ms |
154332 KB |
Output is correct |
35 |
Correct |
205 ms |
146512 KB |
Output is correct |
36 |
Correct |
272 ms |
154452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
839 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
926 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |