#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
// O(n^2) dp
ll max_weights(int n, int m, vi X, vi Y, vi W){
ll mat[n][n]; //position of all fishes
ms(mat, 0, sizeof(mat));
FOR(i,0,m){
mat[X[i]][Y[i]] = W[i];
}
ll dp[n][n][2];
// dp[i][j][0] - mat[i][j] chosen, while increasing
// dp[i][j][1] - while decreasing
ms(dp,0,sizeof(dp));
FOR(i,0,n){
//decreasing
if (i > 0){
FOR(k,0,i-1){
dp[i][n-1][1] = max(dp[i][n-1][1], dp[k][n-1][0]);
dp[i][n-1][1] = max(dp[i][n-1][1], dp[k][0][1]);
}
dp[i][n-1][1] += mat[i][n-1];
ROF(j,n-2,0){
dp[i][j][1] = max(dp[i][j][1], dp[i][j+1][1]);
dp[i][j][1] = max(dp[i][j][1], dp[i-1][j+1][1]);
dp[i][j][1] += mat[i][j];
}
}
if (i < n-1){
//increasing
if (i>1) dp[i][0][0] = max(dp[i][0][0], dp[i-1][0][1]);
if (i>2) dp[i][0][0] = max(dp[i][0][0], dp[i-2][n-1][0]);
dp[i][0][0] += mat[i][0];
FOR(j,1,n){
dp[i][j][0] = max(dp[i][j][0], dp[i][j-1][0]);
if (i>0){
dp[i][j][0] = max(dp[i][j][0], dp[i-1][j-1][0]);
}
dp[i][j][0] += mat[i][j];
}
}
}
ll ans = 0;
FOR(i,0,n){
FOR(j,0,n){
ans = max(ans, max(dp[i][j][0], dp[i][j][1]));
}
}
if (n > 2){
ll val = 0;
FOR(i,0,n){
val += mat[n-1][i];
}
ans = max(ans, dp[n-3][0][1] + val);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
777 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
811 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
757 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
2388 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
2388 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
2360 KB |
Output is correct |
15 |
Correct |
2 ms |
2388 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
16 ms |
4160 KB |
Output is correct |
18 |
Correct |
16 ms |
4148 KB |
Output is correct |
19 |
Correct |
14 ms |
4176 KB |
Output is correct |
20 |
Correct |
14 ms |
4132 KB |
Output is correct |
21 |
Correct |
15 ms |
4180 KB |
Output is correct |
22 |
Correct |
26 ms |
5940 KB |
Output is correct |
23 |
Correct |
5 ms |
2636 KB |
Output is correct |
24 |
Correct |
12 ms |
3540 KB |
Output is correct |
25 |
Correct |
2 ms |
2388 KB |
Output is correct |
26 |
Correct |
5 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
2388 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
2360 KB |
Output is correct |
15 |
Correct |
2 ms |
2388 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
16 ms |
4160 KB |
Output is correct |
18 |
Correct |
16 ms |
4148 KB |
Output is correct |
19 |
Correct |
14 ms |
4176 KB |
Output is correct |
20 |
Correct |
14 ms |
4132 KB |
Output is correct |
21 |
Correct |
15 ms |
4180 KB |
Output is correct |
22 |
Correct |
26 ms |
5940 KB |
Output is correct |
23 |
Correct |
5 ms |
2636 KB |
Output is correct |
24 |
Correct |
12 ms |
3540 KB |
Output is correct |
25 |
Correct |
2 ms |
2388 KB |
Output is correct |
26 |
Correct |
5 ms |
2644 KB |
Output is correct |
27 |
Correct |
215 ms |
211736 KB |
Output is correct |
28 |
Correct |
69 ms |
22328 KB |
Output is correct |
29 |
Correct |
280 ms |
224196 KB |
Output is correct |
30 |
Correct |
333 ms |
224308 KB |
Output is correct |
31 |
Correct |
284 ms |
224224 KB |
Output is correct |
32 |
Correct |
85 ms |
19424 KB |
Output is correct |
33 |
Correct |
296 ms |
224344 KB |
Output is correct |
34 |
Correct |
298 ms |
224316 KB |
Output is correct |
35 |
Correct |
233 ms |
216436 KB |
Output is correct |
36 |
Correct |
281 ms |
224244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
757 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
777 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |