이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, M;
vector<int> X, Y, W;
vector<vector<ll>> ps, v, dp;
ll get_score(int l, int r, int hl, int hr)
{
if (l < 0) return 0;
const int mx_h = max(hl, hr);
if (l == r - 2)
return dp[l][hl] - ps[l+1][hl] + ps[l+1][mx_h];
return dp[l][hl] + ps[r-1][hr];
}
ll max_weights(int N_, int M_, vector<int> X_, vector<int> Y_, vector<int> W_)
{
N = N_; M = M_;
X = X_; Y = Y_; W = W_;
ps = v = vector<vector<ll>>(N+1, vector<ll>(N));
for (int i = 0; i < M; i++)
v[X[i]][Y[i]] = W[i];
for (int i = 0; i < N; i++)
{
ll sum = 0;
for (int j = 0; j < N; j++)
{
sum += v[i][j];
ps[i][j] = sum;
}
}
dp = vector<vector<ll>>(N, vector<ll>(N));
ll res = 0;
for (int i = 0; i < N; i++)
{
dp[0][i] = ps[1][i];
res = max(res, dp[0][i]);
}
for (int r = 1; r < N; r++)
{
for (int hr = 0; hr < N; hr++)
{
ll mx = max(ps[r-1][hr], dp[r-1][N-1] - ps[r][hr]);
for (int l = r - 3; l < r - 1; l++)
{
if (l < 0) continue;
for (int hl = 0; hl < N; hl++)
mx = max(mx, get_score(l, r, hl, hr));
}
dp[r][hr] = ps[r+1][hr] + mx;
res = max(res, dp[r][hr]);
}
}
return res;
}
# | 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... |