제출 #42704

#제출 시각아이디문제언어결과실행 시간메모리
42704repeating수열 (APIO14_sequence)C++11
11 / 100
2033 ms17260 KiB
#include <bits/stdc++.h> #define F first #define S second #define P push #define pb push_back #define MEM(dp,i) memset(dp,i,sizeof(dp)) #define W while #define R return #define C continue #define SI size() #define ll long long #define ld long double #define pll pair<ll,ll> #define pii pair<int,int> #define SF(x) scanf("%Id",&x) #define SF2(x,y) scanf("%Id%Id",&x,&y) #define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z) #define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o) #define all(v) v.begin(),v.end() using namespace std; const long long INF = 1e9+1; const long long MOD = 1e9+7; const int MX=100015; ll a[MX]; ll n,m; ll SUM; vector<ll> v; ll val; ll dp[10005][202]; ll su[10005]; ll DP(ll x,ll k){ if(k==0)R 0; if(x==n)R -INF; ll sum=0; ll &ret=dp[x][k]; if(ret!=-1)R ret; ret=-INF; ll z; for(int i=x;i<n;i++){ z=DP(i+1,k-1); // cout<<z<<endl; if(z==-INF)break; sum+=a[i]; if(val>sum)continue; ret=max(ret,z+(sum*su[i+1])); // cout<<sum*su[i+1]<<endl; } R ret; } void fs(ll x,ll k){ if(k==0)R; ll sum=0; ll ret=dp[x][k]; ll z; for(int i=x;i<n;i++){ z=DP(i+1,k-1); if(z==-INF)break; sum+=a[i]; if(val>sum)continue; if(ret==z+(sum*su[i+1])){ cout<<i+1<<" "; fs(i+1,k-1); R; } } } ll solve(){ ll l=0,r=1e9+1; W(l<r){ // l=5,r=5; ll mid=(l+r)/2; ll k=m+1; for(int i=0;i<n;i++){ ll sum=0; W(i<n){ sum+=a[i]; if(sum>=mid){ k--; break; } i++; } if(k==0){ val=mid; l=mid+1; break; } } if(k){ r=mid; } } ll res=DP(0,m); R res; } int main(){ MEM(dp,-1); cin>>n>>m; for(ll i=0;i<n;i++){ cin>>a[i]; SUM+=a[i]; } for(ll i=n-1;i>=0;i--) su[i]=su[i+1]+a[i]; ll z=SUM; ll res=solve(); cout<<res<<endl; fs(0,m); }

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

sequence.cpp: In function 'int main()':
sequence.cpp:108:8: warning: unused variable 'z' [-Wunused-variable]
     ll z=SUM;
        ^
#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...