#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define en '\n'
#define all(a) a.begin() , a.end()
#define fi first
#define se second
using namespace std;
ll dp[301][10][10][10];
ll ps[301][10];
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
int tmx = 0;
bool ok = 1;
for(int i = 0; i < m; ++i){
x[i]++;
y[i]++;
}
for(int i = 0; i < m; ++i){
tmx = max(tmx, x[i]);
if(x[i] % 2 == 0) ok = 0;
}
if(ok){
ll ans = 0;
for(int i = 0; i < m; ++i){
ans += w[i];
}
return ans;
}
if(tmx <= 2){
ll ans1 = 0;
ll ans2 = 0;
for(int i = 0; i < m; ++i){
if(x[i] == 1) ans1 += w[i];
else ans2 += w[i];
}
return max(ans1, ans2);
}
int tmy = 0;
for(int i = 0; i < m; ++i){
tmy = max(tmy, y[i]);
}
if(tmy <= 9){
for(int i = 0; i < m; ++i){
ps[x[i]][y[i]] += w[i];
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= 9; ++j) ps[i][j] += ps[i][j - 1];
}
for(int i = 0; i <= 9;++i){
for(int j = 0; j <= 9; ++j){
for(int z = 0; z <= 9; ++z){
dp[3][i][j][z] = max(0ll, ps[1][j] - ps[1][i]) + max(0ll, ps[2][max(i, z)] - ps[2][j]) + max(0ll, ps[3][j] - ps[3][z]);
}
}
}
for(int i = 4; i <= n; ++i){
ll mx[10][10];
for(ll j = 0; j <= 9; ++j){
for(ll z = 0; z <= 9; ++z) mx[j][z] = 0;
}
for(ll j = 0; j <= 9; ++j){
for(ll z = 0; z <= 9; ++z){
for(ll f = 0; f <= 9; ++f){
mx[z][f] = max(mx[z][f], dp[i - 1][j][z][f]);
}
}
}
for(ll j = 0; j <= 9; ++j){
for(ll z = 0; z <= 9; ++z){
for(ll f = 0; f <= 9; ++f){
dp[i][j][z][f] = mx[j][z] + max(0ll, ps[i - 1][f] - ps[i - 1][max(z, j)]) + max(0ll, ps[i][z] - ps[i][f]);
}
}
}
}
ll ans = 0;
for(int i = 0; i <= 9; ++i){
for(int j = 0; j <= 9; ++j){
for(int z = 0;z <= 9; ++z){
ans = max(ans, dp[n][i][j][z]);
}
}
}
return ans;
}
}
// int main(){
// int n, m; cin >> n >> m;
// vector<int> x(m), y(m), w(m);
// for(int i = 0; i < m; ++i) cin >> x[i];
// for(int i = 0; i < m; ++i) cin >> y[i];
// for(int i = 0; i < m; ++i) cin >> w[i];
// cout << max_weights(n, m, x, y, w);
// }
Compilation message (stderr)
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
90 | }
| ^
# | 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... |