이 제출은 이전 버전의 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 -(1ll << 59);
if (l == r - 2)
return dp[l][hl] + ps[r-1][max(hl, hr)];
else
{
if (hr < hl)
return dp[l][hl] + ps[r][hl] - ps[r][hr];
else
return dp[l][hl] + ps[r-1][hr] - ps[r-1][hl];
}
}
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++)
{
res = max(res, ps[1][i]);
}
for (int r = 1; r < N; r++)
{
for (int hr = 0; hr < N; hr++)
{
ll mx = ps[r-1][hr];
for (int hl = 0; hl < N; hl++)
mx = max(mx, get_score(r-2, r, hl, hr));
for (int hl = 0; hl < N; hl++)
mx = max(mx, get_score(r-1, r, hl, hr));
dp[r][hr] = mx;
res = max(res, dp[r][hr] + ps[r+1][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... |