이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |