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>
#define int long long
using namespace std;
vector<int> a;
vector<vector<vector<int>>> memo;
int N,M;
int dp(int x, int last, int lastlast){
if(memo[x][last][lastlast]!=-1) return memo[x][last][lastlast];
if(x==N){
if(last&&!lastlast) return memo[x][last][lastlast]=a[x-2];
if(!last&&lastlast) return memo[x][last][lastlast]=a[x-1];
return memo[x][last][lastlast]=0;
}
int take=dp(x+1, 1, last);
if(last==0&&x>0) take+=a[x-1];
int notake=dp(x+1, 0, last);
if(lastlast==1&&last==0) notake+=a[x-1];
return memo[x][last][lastlast] = max(take, notake);
}
long long max_weights(signed n, signed m, std::vector<signed> X, std::vector<signed> Y, std::vector<signed> W) {
N=n; M=m;
a.resize(N, 0);
memo.resize(N+1, vector<vector<int>>(2, vector<int>(2,-1)));
for (int i = 0; i < M; i++) a[X[i]] = W[i];
int p=dp(0,0,0);
return p;
}
# | 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... |