이 제출은 이전 버전의 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 h1, int h2)
{
if (l < 0) return 0;
const int mn_h = min(h1, h2);
if (l == r - 1)
return dp[l][h1] - ps[r][mn_h] - ps[l][mn_h];
if (l == r - 2)
return dp[l][h1] - ps[l+1][mn_h];
return dp[l][h1];
}
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_;
v = vector<vector<ll>>(N+1, vector<ll>(N));
for (int i = 0; i < M; i++)
v[X[i]][Y[i]] = W[i];
ps = vector<vector<ll>>(N+1, vector<ll>(N));
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 i = 1; i < N; i++)
{
for (int j = 0; j < N; j++)
{
ll mx = 0;
for (int l = i - 3; l < i; l++)
{
if (l < 0) continue;
for (int h = 0; h < N; h++)
{
mx = max(mx, get_score(l, i, h, j));
}
}
dp[i][j] = ps[i-1][j] + ps[i+1][j] + mx;
res = max(res, dp[i][j]);
}
}
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... |