이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
vector<vector<int>> c(N + 1, vector<int>(N + 1));
for(int i = 0; i < M; ++i) {
c[X[i]][Y[i]] = W[i];
}
vector<vector<long long>> dp(N + 1, vector<long long>(N + 1)), bestdp;
bestdp = dp;
dp[0][0] = 0;
bestdp[0][0] = 0;
for(int i = 1; i <= N; ++i) {
dp[0][i] = dp[0][i - 1] + c[1][i - 1];
bestdp[0][i] = max(bestdp[0][i - 1], dp[0][i]);
}
for(int i = 1; i < N; ++i) {
dp[i][0] = 0;
for(int j = 0; j <= N; ++j) {
dp[i][0] = max(dp[i][0], dp[i - 1][j]);
}
bestdp[i][0] = dp[i][0];
for(int j = 1; j <= N; ++j) {
dp[i][j] = dp[i - 1][j] - c[i][j - 1];
dp[i][j] = max(dp[i][j], (i - 2 < 0 ? 0 : bestdp[i - 2][j - 1]) + c[i - 1][j - 1]);
dp[i][j] = max(dp[i][j], (i - 2 < 0 ? 0 : bestdp[i - 2][N]));
dp[i][j] += c[i + 1][j - 1];
bestdp[i][j] = max(bestdp[i][j - 1], dp[i][j]);
}
}
return bestdp[N - 1][N];
}
# | 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... |