제출 #111042

#제출 시각아이디문제언어결과실행 시간메모리
111042aleksami수열 (APIO14_sequence)C++14
22 / 100
19 ms3584 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct lajn { ll k; ll n; int idx; }; #define MAXN 100005 #define MAXK 205 deque <lajn> q; ll a[MAXN]; ll dp[MAXN][MAXK]; int opt[MAXN][MAXK]; ll f(ll k,ll n,ll x) { return k*x+n; } bool useless(ll x) { lajn a = q.front(); q.pop_front(); lajn b = q.front(); q.push_front(a); if(f(a.k,a.n,x)<=f(b.k,b.n,x))return true; return false; } void calc(int idx,int n) { q.clear(); for(int i = 1; i <= n; i++) { lajn aa; if(i!=n){aa.k=a[i]; aa.n=-a[i]*a[i]+dp[idx-1][i]; aa.idx=i; q.push_back(aa); } while(1) { if(q.size()<=1)break; if(useless(a[i]))q.pop_front(); else break; } if(q.size()>0) { lajn aa = q.front(); dp[idx][i]=f(aa.k,aa.n,a[i]); opt[idx][i]=aa.idx; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,k; cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; a[i]+=a[i-1]; } for(int i = 1; i <= k; i++) { calc(i,n); } cout << dp[k][n] << "\n"; int now = n; while(k > 0) { cout << opt[k][now] << " "; now = opt[k][now]; k--; } 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...