#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void maxup(ll &a, ll b) {
a = max(a, b);
}
long long max_weights(int n, int cnt_fish, std::vector<int> XX, std::vector<int> YY, std::vector<int> WW) {
n += 7;
vector<set<int>> interestingSet(n);
vector<vector<int>> interesting(n);
vector<vector<vector<ll>>> dp(2, vector<vector<ll>> (n));
vector<ll> dp_zero(n, 0LL);
vector<vector<pair<int, ll>>> pe(n);
assert((int) XX.size() == cnt_fish);
assert((int) YY.size() == cnt_fish);
assert((int) WW.size() == cnt_fish);
vector<vector<int>> mtr(11, vector<int> (11, 0));
for (int i = 0; i < cnt_fish; i++) {
int x = XX[i] + 5, y = YY[i] + 1, w = WW[i];
mtr[11 - y][x] = w;
///cout << " \t\t\t\t ---> " << x << " " << y << " " << w << "\n";
pe[x].push_back({y, w});
vector<int> xs = {x - 1, x + 1};
for (auto &i : xs) {
interestingSet[i].insert(y);
}
}
for (int i = 0; i < 11 && 0; i++) {
for (int j = 0; j < 11; j++) {
if (mtr[i][j] == 0 && 1) {
cout << " ";
} else {
cout << mtr[i][j];
}
}
cout << "\n";
}
for (int x = 0; x < n; x++) {
interestingSet[x].insert(0);
for (auto &y : interestingSet[x]) {
interesting[x].push_back(y);
}
dp[0][x].resize((int) interesting[x].size(), 0LL);
dp[1][x].resize((int) interesting[x].size(), 0LL);
sort(pe[x].begin(), pe[x].end());
ll sum = 0;
for (auto &it : pe[x]) {
sum += it.second;
it.second = sum;
}
}
function<ll(int, int)> get = [&] (int x, int y) {
if (x == n) {
return 0LL;
}
assert(0 <= x && x < n);
assert(0 <= y && y < n);
ll sol = 0;
int low = 0, high = (int) pe[x].size() - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (pe[x][mid].first <= y) {
sol = pe[x][mid].second;
low = mid + 1;
} else {
high = mid - 1;
}
}
return sol;
};
for (int i = 5; i < n - 2; i++) {
/// compute dp_zero[i]
{
maxup(dp_zero[i], dp_zero[i - 1]);
for (int ant_j = 0; ant_j < (int) interesting[i - 1].size(); ant_j++) {
int h2 = interesting[i - 1][ant_j];
if (dp[0][i - 1][ant_j] == 9) {
/// cout << " -> " << i - 1 << " " << ant_j << "\n";
}
maxup(dp_zero[i], dp[0][i - 1][ant_j]);
maxup(dp_zero[i], dp[1][i - 1][ant_j]);
}
/// cout << i << " -> " << dp_zero[i] << "\n";
/** if (dp_zero[i] == ) {
///exit(0);
}**/
}
{
for (int j = 0; j < (int) interesting[i].size(); j++) {
int h = interesting[i][j];
{
/// ant == 0
ll dp_ant0 = 0;
{
/// 0 0 h
maxup(dp_ant0, dp_zero[i - 2] + get(i - 1, h) + get(i + 1, h));
/**if (dp_ant0 == 9) {
cout << "lol : " << i - 2 << " : " << dp_zero[i - 2] << "\n";
exit(0);
}**/
}
{
/// h2 0 h
for (int ant_j = 0; ant_j < (int) interesting[i - 2].size(); ant_j++) {
int h2 = interesting[i - 2][ant_j];
if (h <= h2) {
maxup(dp_ant0, dp[0][i - 2][ant_j] + get(i + 1, h));
maxup(dp_ant0, dp[1][i - 2][ant_j] + get(i + 1, h));
} else {
maxup(dp_ant0, dp[0][i - 2][ant_j] + (get(i - 1, h) - get(i - 1, h2)) + get(i + 1, h));
maxup(dp_ant0, dp[1][i - 2][ant_j] + (get(i - 1, h) - get(i - 1, h2)) + get(i + 1, h));
}
}
}
/** if (i == 10 && j == 1) {
cout << " -> " << dp_ant0 << "\n";
exit(0);
}**/
maxup(dp[0][i][j], dp_ant0);
maxup(dp[1][i][j], dp_ant0);
/**if (i == 7 && j == 2) {
cout << "h = " << h << "\n";
cout << dp_ant0 << "\n";
exit(0);
}*/
///if (i == 5 && h == )
}
{
/// ant != 0
/// h2 h
/// h3 h2 h
/// h2 > h
/**
*
* *
* * *
* * *
* * *
**/
for (int ant_j = 0; ant_j < (int) interesting[i - 1].size(); ant_j++) {
int h2 = interesting[i - 1][ant_j];
{
/// dp[0][i][j]
if (h2 >= h) {
maxup(dp[0][i][j], dp[0][i - 1][ant_j] - get(i, h2) + get(i + 1, h));
maxup(dp[0][i][j], dp[1][i - 1][ant_j] - get(i, h2) + get(i + 1, h));
}
}
{
/// dp[1][i][j]
if (h2 <= h) {
maxup(dp[1][i][j], dp[1][i - 1][ant_j] - get(i, h2) + (get(i - 1, h) - get(i - 1, h2)) + get(i + 1, h));
}
}
}
}
/**if (i == 10 && j == 1) {
cout << " : " << dp[0][i][j] << " vs " << dp[1][i][j] << "\n";
exit(0);
}**/
}
}
}
ll sol = 0;
for (int i = 0; i < n; i++) {
maxup(sol, dp_zero[i]);
for (int j = 0; j < (int) interesting[i].size(); j++) {
maxup(sol, dp[0][i][j]);
maxup(sol, dp[1][i][j]);
}
}
return sol;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:93:13: warning: unused variable 'h2' [-Wunused-variable]
93 | int h2 = interesting[i - 1][ant_j];
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
31396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
70 ms |
35288 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
29160 KB |
Output is correct |
2 |
Runtime error |
23 ms |
30584 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
29160 KB |
Output is correct |
2 |
Runtime error |
23 ms |
30584 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
31396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |