이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
int n=N;int m=M;
long long dp[n][n][2];
memset(dp,0,sizeof dp);
long long grid[n][n];
memset(grid,0,sizeof grid);
for (int i = 0; i < m; ++i)
{
grid[X[i]][Y[i]]=W[i];
}
long long pre[n][n];
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
pre[i][j]=(j ? pre[i][j-1] : 0)+grid[i][j];
}
}
long long ans=0;
int prev[n];
memset(prev,0,sizeof prev);
for (int i = 1; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
for (int k = 0; k < n; ++k)
{
if(k>j){
dp[i][j][1]=max(dp[i][j][1],max(dp[i-1][k][0],dp[i-1][k][1])+pre[i][k]-(j>0 ? pre[i][j-1] : 0ll));
if(j==0) {
if(dp[i][j][0]<max(dp[i-1][k][0],dp[i-1][k][1])+pre[i][k]){
prev[i]=k;
}
dp[i][j][0]=max(dp[i][j][0],max(dp[i-1][k][0],dp[i-1][k][1])+pre[i][k]);
}
}else if(k<j){
if(k==0){
dp[i][j][0]=max(dp[i][j][0],dp[i-1][k][0]+pre[i-1][j]-min(pre[i-1][j],pre[i-1][prev[i-1]]));
}else{
dp[i][j][0]=max(dp[i][j][0],dp[i-1][k][0]+pre[i-1][j]-(k>0 ? pre[i-1][k-1] : 0ll));
}
}else {
dp[i][j][0]=max(dp[i][j][0],dp[i-1][k][0]);
dp[i][j][1]=max(dp[i][j][1],max(dp[i-1][k][0],dp[i-1][k][1]));
}
}
//cout <<i<<" "<<j<<" "<<dp[i][j][0]<<" "<<dp[i][j][1]<<endl;
ans=max(ans,dp[i][j][0]);
ans=max(ans,dp[i][j][1]);
}
}
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... |