제출 #855479

#제출 시각아이디문제언어결과실행 시간메모리
855479vjudge1수열 (APIO14_sequence)C++17
39 / 100
2082 ms32092 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define int long long #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NET r < tl || tr < l #define double long double using namespace std; const int N=1e5+7; const int mod=1e9+7; const int inf=1e18; void AlemAmenov(){ int n, k; cin >> n >> k; int a[n+1]; int pref[n+1]={}; for(int i=1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i-1] + a[i]; } int suf[n+2]={}; for(int i=n; i >= 1; i--){ suf[i] = suf[i+1] + a[i]; } int dp[n+1][k+1] = {}; int p[n+1][k+1] = {}; for(int i=1; i < n; i++){ dp[i][1] = pref[i] * suf[i+1]; } int mx=0; for(int kk=2; kk <= k; kk++){ for(int i=kk; i <= n; i++){ for(int j=1; j < i; j++){ if ( dp[i][kk] < dp[j][kk-1] + (pref[i]-pref[j])*(suf[i+1]) ){ dp[i][kk] = dp[j][kk-1] + (pref[i]-pref[j])*(suf[i+1]); p[i][kk] = j; } if ( dp[mx][k] < dp[i][k] )mx = i; } } } cout << dp[mx][k] << '\n'; while(k){ cout << mx << ' '; mx = p[mx][k--]; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("262144.in", "r", stdin); // freopen("262144.out", "w", stdout); int RealName=1; // cin >> RealName; while(RealName--){ //cout << "Case " << ++C << ":\n"; AlemAmenov(); } 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...