제출 #989380

#제출 시각아이디문제언어결과실행 시간메모리
989380cnn008수열 (APIO14_sequence)C++17
0 / 100
54 ms62548 KiB
#include "bits/stdc++.h" using namespace std; #ifdef N_N_C #include "debug.h" #else #define cebug(...) "Arya" #endif #define ll long long const int N=1e5+5; const int mod=1e9+7; int n,k,a[N],op[205][N]; ll dp[205][N],p[N]; void dnc(int j, int l, int r, int optl, int optr){ if(l>r) return; int mid=(l+r)>>1; pair <ll,int> opt={0,-1}; for(int x=min(mid,optr); x>=optl; x--) opt=max(opt,{dp[j-1][x-1]+(p[mid]-p[x-1])*(p[n]-p[mid]),x}); dp[j][mid]=opt.first; op[j][mid]=opt.second; dnc(j,l,mid-1,optl,opt.second); dnc(j,mid+1,r,opt.second,optr); } vector <int> trc; void trace(int j, int val){ if(!j) return; int pos=0; for(int i=1; i<=n; i++) if(dp[j][i]==val) pos=i; if(pos==n) pos--; trc.push_back(pos); trace(j-1,dp[j-1][op[j][pos]-1]); } void sol(){ cin>>n>>k; for(int i=1; i<=n; i++) cin>>a[i],p[i]=p[i-1]+a[i]; for(int j=1; j<=k; j++) dnc(j,j,n,1,n); ll ans=0; for(int i=1; i<=n; i++) ans=max(ans,dp[k][i]); cout<<ans<<"\n"; trace(k,ans); reverse(trc.begin(),trc.end()); for(auto x:trc) cout<<x<<" "; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("sequence.in", "r", stdin); // freopen("sequence.out", "w", stdout); int tt=1; //cin>>tt; while(tt--){ sol(); } cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; return 0; }
#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...