제출 #547036

#제출 시각아이디문제언어결과실행 시간메모리
547036ala2수열 (APIO14_sequence)C++14
50 / 100
461 ms20056 KiB
#include <bits/stdc++.h> #define int long long #define F first #define S second #define pb push_back #define B begin() #define E end() using namespace std; int n,K; const int inf=-1e15; int p[1001000]; int a[1001000]; int dp[1012][1012]; int H; int mul(int i,int j) { return (p[j]-p[i]+a[i])*(p[n-1]-p[j]); } int f(int i,int k) { if(k<0) return inf; if(i>=n-1) return 0; if(dp[i][k]!=-1) return dp[i][k]; int mx=0; for(int j=i;j<n-1;j++) { mx=max(mx,mul(i,j)+f(j+1,k-1)); } return dp[i][k]=mx; } void Do(int i,int k) { // cout<<" LL "<<i<<" "<<k<<endl; if(k<=0) return ; if(i>=n-1) return ; for(int j=i;j<n-1;j++) { // cout<<" "<<mul(i,j)<<" "<<f(j+1,k-1)<<" "<<endl; if(mul(i,j)+f(j+1,k-1)==f(i,k)) { cout<<j+1<<" "; Do(j+1,k-1); return ; } } } signed main() { memset(dp,-1,sizeof dp); cin>>n>>K; for(int i=0;i<n;i++) cin>>a[i]; p[0]=a[0]; for(int i=1;i<n;i++) p[i]=p[i-1]+a[i]; cout<<f(0,K)<<endl; H=f(0,K); Do(0,K); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...