이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define MAXN 100007
using namespace std;
int n,m,maxx;
long long sum[MAXN],dp[MAXN];
bool li[MAXN];
long long ff(int pos){
if(pos==-1)return 0;
if(li[pos])return dp[pos];
li[pos]=true;
dp[pos]=ff(pos-1);
if(pos==n-1){
dp[pos]=max(dp[pos],ff(pos-2)+sum[pos]);
}else if(pos>=2){
dp[pos]=max(dp[pos], max(ff(pos-3)+sum[pos]+sum[pos-1],ff(pos-2)+sum[pos]) );
}else if(pos==1){
dp[pos]=max(dp[pos],ff(pos-2)+sum[pos]);
}else if(pos==0){
dp[pos]=max(dp[pos],ff(pos-1)+sum[pos]);
}
return dp[pos];
}
long long max_weights(int N, int M,vector<int> X,vector<int> Y,vector<int> W){
n=N; m=M;
for(int i=0;i<m;i++){
sum[X[i]]+=W[i];
maxx=max(maxx,X[i]);
}
if(n==2 or maxx==1)return max(sum[0],sum[1]);
return ff(n-1);
}
/*
int main(){
cout<<max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3})<<"\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... |