This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #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];
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;
dp[i][j][1] = 0;
}
}
FOR(i,0,M){
Y[i]++;
fish[X[i]][Y[i]] = true;
weights[X[i]][Y[i]] = W[i];
}
FOR(i,0,N){
FOR(j,0,N+1){
FOR(k,0,2){
ll temp = 0;
FOR(height,0,N+1){
if (k==0){
if (fish[i][height] && j >= height) temp -= weights[i][height];
if (fish[i+1][height]) temp += weights[i+1][height];
}else{
if (fish[i+1][height]) temp += weights[i+1][height];
if (fish[i][height] && j >= height) temp -= weights[i][height];
if (i > 0 && fish[i-1][height] && j < height) temp += weights[i-1][height];
}
if (height < j) dp[i+1][height][0] = max(dp[i+1][height][0], dp[i][j][k] + temp);
else dp[i+1][height][1] = max(dp[i+1][height][1], dp[i][j][k] + temp);
}
}
}
}
ll ans = 0;
FOR(i,0,N+1) FOR(j,0,N+1)FOR(k,0,2) ans = max(ans, dp[i][j][k]);
return ans;
}
# | 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... |