#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vl = vector<ll>;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define pb push_back
/*
Time log:
- first start: 1048am
- 3/100: 1100am
- first stop: 1128am
- second start: 337pm
- 416pm finally stopped being stupid and got 9/100 (+6 points)
- second end:
- overall time used:
*/
/*
NxN grid of cells
grid[c][r] = the cell at column c row r
grid[0][r] is the westernmost point, and grid[N-1][r] is the easternmost point
grid[c][0] = southernmost point, grid[c][N-1] northermost point
M catfishes
X[i], Y[i] for i < M are column and row of fish i
W[i] = weight of fish i
a catfish can be caught if grid[ci][ri] is empty and grid[ci-1][ri] or grid[ci+1][ri] has a pier tile
a pier extends from grid[cP][0] to grid[cP][rP]
*/
int N, M;
vi X, Y; vector<ll> W;
bool cmp(int a, int b) { // compare two fish in the same col
return Y[a] < Y[b];
}
ll max_weights(int _N, int _M, vi _X, vi _Y, vi _W) {
N = _N; M = _M; X = _X; Y = _Y; for (int i = 0; i < M; i++) W.pb(ll(_W[i]));
// subtask 3: y[i] = 0 for all i, so just do a dp where DP[i][use] = max(DP[i-2][use] + W[i], DP[i-1][!use] + w[i])
vl Weights(N+2, 0LL); for (int i = 0; i < M; i++) Weights[X[i]+1] = W[i];
ll DP[N+1]; // 0 for use, 1 for not use
DP[0] = 0LL;
DP[1] = Weights[0] + Weights[2];
for (int i = 2; i <= N; i++) {
ll useval = Weights[i - 1] + Weights[i + 1];
DP[i] = max(DP[i - 2] + useval - Weights[i - 1], DP[i - 1]);
}
return DP[N];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |