이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 1e3+20;
const int MAXK = 210;
const int LOG = 20;
const int MOD = 1e9+7;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
int n, k;
int a[MAXN], pr[MAXN];
int dp[MAXN][MAXK], ba[MAXN][MAXK];
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> a[i]; pr[i] = pr[i-1]+a[i];
}
for(int i=0; i<=n+1; i++)
for(int j=1; j<=k+1; j++) ba[i][j] = -1;
for(int i=2; i<=n; i++){
for(int m=1; m<=min(k, i-1); m++){
dp[i][m] = -INF;
for(int j=1; j<=i-1; j++){
if(ba[j][m-1] == -1) continue; // gk ada ke belakangnya
if(dp[j][m-1] + pr[j] * (pr[i]-pr[j]) > dp[i][m]){ // cek yg optimal potong dmn
dp[i][m] = dp[j][m-1] + pr[j] * (pr[i]-pr[j]); // cmn ngebuild sampe dp[i][i-1]
ba[i][m] = j;
}
}
//cout << dp[i][m] <<' ' << i << ' ' << m << '\n';
}
}
cout << dp[n][k] << '\n';
vector <int> vec;
int nw = n;
for(int i=k; i>=1; i--){
nw = ba[nw][i];
cout << nw << ' ';
}
cout << '\n';
}
# | 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... |