제출 #208050

#제출 시각아이디문제언어결과실행 시간메모리
208050rzbt수열 (APIO14_sequence)C++14
71 / 100
129 ms131076 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 100005 #define MAXK 205 typedef long long ll; using namespace std; ll n,u; ll dp[MAXN][MAXK]; ll niz[MAXN]; ll suma[MAXN]; ll sec[MAXN][MAXK]; pair<ll,ll> prava[MAXN][MAXK]; vector<pair<pair<ll,ll>,ll> > prave; int main() { scanf("%lld %lld", &n, &u); for(ll i=1;i<=n;i++) scanf("%lld",niz+i); for(ll i=1;i<=n;i++) suma[i]=suma[i-1]+niz[i]; for(ll k=1;k<=u;k++){ prave.clear(); for(ll d=k+1;d<=n;d++){ pair<ll,ll> t=mp(suma[d-1],-suma[d-1]*suma[d-1]+dp[d-1][k-1]); prava[d-1][k-1]=t; while(!prave.empty()){ pair<ll,ll> posl=prava[prave.back().S][k-1]; if(posl.F==t.F){ prave.pop_back(); continue; } ll presek=(posl.S-t.S)/(t.F-posl.F)+((posl.S-t.S)%(posl.F-t.F)==0?0:1); if(presek>10000000000000000ll)exit(2); if(presek<=prave.back().F.F){ prave.pop_back(); continue; } prave.back().F.S=presek-1; prave.pb(mp(mp(presek,10000000000000000ll),d-1)); break; } if(prave.empty()){ prave.pb(mp(mp(0ll,10000000000000000ll),d-1)); } ll l=0,r=prave.size()-1,sol=-1; while(l<=r){ ll mid=(l+r)/2; if(prave[mid].F.F<=suma[d]){ sol=prave[mid].S; l=mid+1; }else r=mid-1; } dp[d][k]=prava[sol][k-1].F*suma[d]+prava[sol][k-1].S; sec[d][k]=sol; /** dp[d][k]=-1; for(ll i=k+1;i<=d;i++){ ll tr=suma[i-1]*(suma[d]-suma[i-1])+dp[i-1][k-1]; if(tr>dp[d][k]){ sec[d][k]=i-1; dp[d][k]=tr; } } */ //printf(" %lld %lld %lld\n",d,k,dp[d][k]); /*for(auto x:prave){ printf(" %lld %lld %lld %lld\n",x.F.F,x.F.S,prava[x.S][k-1].F,prava[x.S][k-1].S); } printf("\n");*/ } } printf("%lld\n",dp[n][u]); ll poc=n; for(ll i=u;i>0;i--){ poc=sec[poc][i]; printf("%lld ",poc); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &n, &u);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",niz+i);
         ~~~~~^~~~~~~~~~~~~~
#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...