제출 #879614

#제출 시각아이디문제언어결과실행 시간메모리
879614JakobZorz수열 (APIO14_sequence)C++14
100 / 100
1447 ms83284 KiB
#include<iostream> #include<vector> #include<queue> #include<stack> #include<algorithm> #include<limits.h> #include<math.h> #include<map> #include<set> #include<unordered_map> #include<unordered_set> #include<iomanip> #include<cstring> typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; //const int MOD=1e9+7; //typedef pair<ll,ll>Point; //typedef pair<ll,ll>Line; //#define x first //#define y second int n,k; ll dp[100001][3]; int chosen[100001][201]; int arr[100000]; ll ps[100001]; void fill(int j,int si,int ei,int sp,int ep){ int m=(si+ei)/2; for(int i2=sp;i2<min(m,ep);i2++){ ll curr=dp[i2][0]+ps[i2]*(ps[m]-ps[i2]); if(curr>=dp[m][1]){ dp[m][1]=curr; chosen[m][j]=i2; } } if(si<ei-1){ fill(j,si,m,sp,chosen[m][j]+1); fill(j,m,ei,chosen[m][j]-1,ep); } } void solve(){ cin>>n>>k; for(int i=0;i<n;i++) cin>>arr[i]; for(int i=1;i<=n;i++) ps[i]=ps[i-1]+arr[i-1]; for(int j=1;j<=k;j++){ fill(j,0,n+1,0,n+1); for(int i=0;i<100001;i++) dp[i][0]=dp[i][1]; } cout<<dp[n][0]<<"\n"; int curr=n; for(int j=k;j>0;j--){ cout<<chosen[curr][j]<<" "; curr=chosen[curr][j]; } cout<<"\n"; } int main(){ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL); //freopen("bank.in","r",stdin);freopen("bank.out","w",stdout); int t=1;//cin>>t; while(t--)solve(); return 0; } /* 7 3 4 1 3 4 0 2 3 */
#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...