이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=1; kk <= k; kk++){
for(int i=kk; i <= n; i++){
for(int j=kk-2; 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |