This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
bool Even = true, Less = true;
for (auto x : X)
{
if (x % 2 != 0)
{
Even = false;
}
if (x > 1)
{
Less = false;
}
}
if (Even)
{
long long sum = 0;
for (auto x : W)
{
sum += x;
}
return sum;
}
if (Less)
{
long long m[N + 3][3];
memset(m, 0, sizeof(m));
for (int i = 0; i < M; i++)
{
m[Y[i]][X[i]] = W[i];
}
for (int i = 1; i < N; i++)
{
m[i][0] += m[i - 1][0];
m[i][1] += m[i - 1][1];
}
long long ans = max(m[N - 1][0], m[N - 1][1]);
if (N == 2)
{
return ans;
}
for (int i = 0; i < N; i++)
{
ans = max(ans, m[i][0] + m[N - 1][1] - m[i][1]);
}
return ans;
}
long long dp[N + 3][3], p[N + 3];
memset(dp, 0, sizeof(dp));
memset(p, 0, sizeof(p));
for (int i = 0; i < M; i++)
{
p[X[i]] = W[i];
}
dp[0][0] = dp[0][1] = 0;
dp[1][0] = p[1];
dp[1][1] = p[0];
for (int i = 2; i < N; i++)
{
dp[i][1] = max({dp[i - 1][0], dp[i - 2][0] + p[i - 1], dp[i - 1][1]});
dp[i][0] = max({dp[i - 1][1] + p[i], dp[i - 1][0]});
}
return max(dp[N - 1][0], dp[N - 1][1]);
}
# | 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... |