// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
const ll maxn = 305;
bool fish[maxn][maxn];
ll weights[maxn][maxn];
ll dp[maxn][maxn][2][2];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
FOR(i,0,maxn){
FOR(j,0,maxn){
fish[i][j] = false;
dp[i][j][0][0] = 0;
dp[i][j][1][0] = 0;
dp[i][j][1][1] = 0;
dp[i][j][0][1] = 0;
}
}
FOR(i,0,M){
Y[i]++;
fish[X[i]][Y[i]] = 1;
weights[X[i]][Y[i]] = W[i];
}
FOR(j,0,N){
FOR(i,0,N+1){
FOR(k,0,2){
FOR(l,0,2){
if (l==1 && k==0) continue;
ll temp = 0;
if (l==1){
FOR(height, 0, N+1){
if (j>0 && fish[j-1][height] && i < height) temp += weights[j-1][height];
if (fish[j+1][height]) temp += weights[j+1][height];
dp[height][j+1][k][0] = max(dp[height][j+1][k][0], dp[i][j][k][l] + temp);
}
}else{
FOR(height, 0, N+1){
if (fish[j][height] && i >= height) temp -= weights[j][height];
if (k != 0 && j>0 && fish[j-1][height] && i < height) temp += weights[j-1][height];
if (fish[j+1][height]) temp += weights[j+1][height];
if (i != 0 && height==0){
dp[i][j+1][1][1] = max( dp[i][j+1][1][1], dp[i][j][k][l]+temp);
}
else if (height<i){
dp[height][j+1][0][0] = max(dp[height][j+1][0][0], dp[i][j][k][l]+temp);
}else if (height >= i) {
dp[height][j+1][1][0] = max(dp[height][j+1][1][0], dp[i][j][k][l]+temp);
}
}
}
}
}
}
}
ll ans = 0;
FOR(i,0,N+1) FOR(j,0,N+1) FOR(k,0,2) FOR(l,0,2){
ans = max(ans, dp[i][j][k][l]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
11868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Runtime error |
36 ms |
18516 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
7256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
24 ms |
3928 KB |
Output is correct |
10 |
Correct |
180 ms |
4188 KB |
Output is correct |
11 |
Correct |
24 ms |
3672 KB |
Output is correct |
12 |
Correct |
182 ms |
4184 KB |
Output is correct |
13 |
Correct |
4 ms |
3420 KB |
Output is correct |
14 |
Correct |
182 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
24 ms |
3928 KB |
Output is correct |
10 |
Correct |
180 ms |
4188 KB |
Output is correct |
11 |
Correct |
24 ms |
3672 KB |
Output is correct |
12 |
Correct |
182 ms |
4184 KB |
Output is correct |
13 |
Correct |
4 ms |
3420 KB |
Output is correct |
14 |
Correct |
182 ms |
3932 KB |
Output is correct |
15 |
Correct |
183 ms |
3928 KB |
Output is correct |
16 |
Correct |
5 ms |
3416 KB |
Output is correct |
17 |
Correct |
260 ms |
4952 KB |
Output is correct |
18 |
Correct |
194 ms |
5544 KB |
Output is correct |
19 |
Correct |
189 ms |
5952 KB |
Output is correct |
20 |
Correct |
190 ms |
5976 KB |
Output is correct |
21 |
Correct |
185 ms |
5724 KB |
Output is correct |
22 |
Correct |
186 ms |
7772 KB |
Output is correct |
23 |
Correct |
211 ms |
4444 KB |
Output is correct |
24 |
Correct |
236 ms |
5208 KB |
Output is correct |
25 |
Correct |
180 ms |
4188 KB |
Output is correct |
26 |
Correct |
198 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
1 ms |
3420 KB |
Output is correct |
8 |
Correct |
1 ms |
3420 KB |
Output is correct |
9 |
Correct |
24 ms |
3928 KB |
Output is correct |
10 |
Correct |
180 ms |
4188 KB |
Output is correct |
11 |
Correct |
24 ms |
3672 KB |
Output is correct |
12 |
Correct |
182 ms |
4184 KB |
Output is correct |
13 |
Correct |
4 ms |
3420 KB |
Output is correct |
14 |
Correct |
182 ms |
3932 KB |
Output is correct |
15 |
Correct |
183 ms |
3928 KB |
Output is correct |
16 |
Correct |
5 ms |
3416 KB |
Output is correct |
17 |
Correct |
260 ms |
4952 KB |
Output is correct |
18 |
Correct |
194 ms |
5544 KB |
Output is correct |
19 |
Correct |
189 ms |
5952 KB |
Output is correct |
20 |
Correct |
190 ms |
5976 KB |
Output is correct |
21 |
Correct |
185 ms |
5724 KB |
Output is correct |
22 |
Correct |
186 ms |
7772 KB |
Output is correct |
23 |
Correct |
211 ms |
4444 KB |
Output is correct |
24 |
Correct |
236 ms |
5208 KB |
Output is correct |
25 |
Correct |
180 ms |
4188 KB |
Output is correct |
26 |
Correct |
198 ms |
4444 KB |
Output is correct |
27 |
Runtime error |
4 ms |
6596 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
7256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
11868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |