이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
int n, m;
vector<int> x, y, w;
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;
int q = min(n, 8+1);
vector<vector<ll>> a(n, vector<ll>(q));
for (int i = 0; i < m; i++) {
a[x[i]][y[i]] = w[i];
}
vector<vector<ll>> sum(n, vector<ll>(q+1));
for (int i = 0; i < n; i++) {
for (int j = 0; j < q; j++) {
sum[i][j+1] = sum[i][j] + a[i][j];
}
}
vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(q+1, vector<ll>(q+1)));
for (int i = 1; i < n; i++) {
for (int j = 0; j <= q; j++) {
for (int j1 = 0; j1 <= q; j1++) {
for (int k = 0; k <= q; k++) {
ll val = dp[i-1][j1][k];
if (j1 > j) val += sum[i][j1] - sum[i][j];
if (j > max(j1, k)) val += sum[i][j] - sum[i][max(j1, k)];
dp[i][j][j1] = max(dp[i][j][j1], val);
}
}
}
}
ll res = 0;
for (int j = 0; j <= q; j++) {
for (int j1 = 0; j1 <= q; j1++) {
res = max(res, dp[n-1][j][j1]);
}
}
for (int i = n-2; i >= n-5 && i >= 0; i--) {
for (int j = 0; j <= q; j++) {
for (int j1 = 0; j1 <= q; j1++) {
ll val = dp[i][j][j1] + sum[i][j];
res = max(res, val);
}
}
}
return res;
}
#ifdef TEST
#include "grader.cpp"
#endif
# | 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... |