Submission #786282

#TimeUsernameProblemLanguageResultExecution timeMemory
786282coding_snorlaxSplit the sequence (APIO14_sequence)C++14
50 / 100
2058 ms36108 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long int; //dp[i][k] : from 1-i, cut k line max answer //dp[i][k] = (List[i]+List[i-1]+...+List[j])^2 + dp[j-1][k-1] //dp[i][0] = (List[i]+...+List[0])^2 //sigma(block[i][j]) = [sigma([i])^2-sigma([i]^2)]//2 vector<ll> List={}; vector<ll> prefix={0}; ll dp[10002][202]={{0}}; ll back_track[10002][202]={{0}}; // dp[i][j][k] : from i to j cut k times max answer //vector<int> answer; void Find_answer(int i,int k){ //cout << i << " " << j << " " << k << "\n"; if(k==0) return; cout << back_track[i][k] << " "; //answer.push_back(back_track[i][j][k][0]+1); Find_answer(back_track[i][k]-1,k-1); } int main(){ ll N,K; cin>>N>>K; for(int i=0;i<N;i++){ ll num; cin>>num; List.push_back(num); prefix.push_back(prefix.back()+num); } for(int i=0;i<N;i++){ for(int k=0;k<=K;k++){ dp[i][k] = 100000000000000; ; } } for(int i=0;i<N;i++) dp[i][0]=(prefix[i+1]-prefix[0]) * (prefix[i+1]-prefix[0]) ; for(int k=1;k<=K;k++){ for(int i=0;i<N;i++){ for(int j=k-1;j<i;j++){ ll Now = dp[j][k-1]+(prefix[i+1]-prefix[j+1])*(prefix[i+1]-prefix[j+1]); //cout <<"i j k" << i << " " << j << " " << k << " " << Now << "\n"; if(Now < dp[i][k]){ back_track[i][k] = j+1; dp[i][k] = Now; } } //cout <<"dp["<<i<<"]["<<k <<"]: " << back_track[i][k] << "\n"; } //cout << "\n"; } cout<<((prefix[N]-prefix[0])*(prefix[N]-prefix[0])-dp[N-1][K])/2<<"\n"; Find_answer(N-1,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...