#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;
unordered_set<ll> fish[maxn];
map<basic_string<ll>, ll> weights;
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){
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]].insert(Y[i]);
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){
if (dp[i][j][k][l] == 0) continue;
FOR(height, 0, N+1){
if (j>0 && fish[j-1].count(height) && i < height) temp += weights[{j-1, height}];
if (fish[j+1].count(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].count(height) && i >= height) temp -= weights[{j, height}];
if (k != 0 && j>0 && fish[j-1].count(height) && i < height) temp += weights[{j-1, height}];
if (fish[j+1].count(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) FOR(j,0,N+1) FOR(k,0,2) FOR(l,0,2){
ans = max(ans, dp[i][j][k][l]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
66 ms |
34656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Runtime error |
145 ms |
63136 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
6488 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3160 KB |
Output is correct |
8 |
Correct |
1 ms |
3160 KB |
Output is correct |
9 |
Correct |
87 ms |
3456 KB |
Output is correct |
10 |
Correct |
827 ms |
3768 KB |
Output is correct |
11 |
Correct |
99 ms |
3416 KB |
Output is correct |
12 |
Correct |
659 ms |
3420 KB |
Output is correct |
13 |
Correct |
12 ms |
3160 KB |
Output is correct |
14 |
Correct |
613 ms |
3528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3160 KB |
Output is correct |
8 |
Correct |
1 ms |
3160 KB |
Output is correct |
9 |
Correct |
87 ms |
3456 KB |
Output is correct |
10 |
Correct |
827 ms |
3768 KB |
Output is correct |
11 |
Correct |
99 ms |
3416 KB |
Output is correct |
12 |
Correct |
659 ms |
3420 KB |
Output is correct |
13 |
Correct |
12 ms |
3160 KB |
Output is correct |
14 |
Correct |
613 ms |
3528 KB |
Output is correct |
15 |
Correct |
511 ms |
3424 KB |
Output is correct |
16 |
Correct |
50 ms |
3672 KB |
Output is correct |
17 |
Execution timed out |
1042 ms |
11856 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3160 KB |
Output is correct |
8 |
Correct |
1 ms |
3160 KB |
Output is correct |
9 |
Correct |
87 ms |
3456 KB |
Output is correct |
10 |
Correct |
827 ms |
3768 KB |
Output is correct |
11 |
Correct |
99 ms |
3416 KB |
Output is correct |
12 |
Correct |
659 ms |
3420 KB |
Output is correct |
13 |
Correct |
12 ms |
3160 KB |
Output is correct |
14 |
Correct |
613 ms |
3528 KB |
Output is correct |
15 |
Correct |
511 ms |
3424 KB |
Output is correct |
16 |
Correct |
50 ms |
3672 KB |
Output is correct |
17 |
Execution timed out |
1042 ms |
11856 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
6488 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
66 ms |
34656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |