이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define vl vector<ll>
#define vll vector<pll>
#define vlll vector<plll>
#define mp make_pair
#define sz(x) (x).size()
#define fr front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
const ll e5=1e5;
const ll e9=1e9;
const ll inf=1e18;
const ll mod=998244353;
const ll N=1e4+10;
const ld pi=3.14159265359;
ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;if(y==1)return x%m;ll p=bpm(x,y/2,m);
if(y%2==0)return p*p%m;else return p*p%mod*x%m;}
ll bp(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll p=bp(x,y/2);
if(y%2==0)return p*p;else return p*p*x;}
ll a[N],b[N],dp[210][N],p[210][N];
void solve() {
ll n,k;
cin>>n>>k;
b[0]=0;dp[0][0]=0;
for(ll i=1;i<=n;i++){
cin>>a[i];
b[i]=b[i-1]+a[i];
dp[0][i]=-inf;
}
for(ll i=1;i<=k+1;i++){
for(ll j=1;j<=n;j++){
ll mx=0;
for(ll ij=0;ij<j;ij++){
if(dp[i-1][ij] + (b[j]-b[ij])*b[ij] > mx){
mx=dp[i-1][ij] + (b[j]-b[ij])*b[ij];
p[i][j]=ij;
}
}
dp[i][j]=mx;
}
}
cout<<dp[k+1][n]<<'\n';
ll x=k+1,y=n;
while(y!=0){
y=p[x][y];
x--;
if(y!=0)cout<<y<<' ';
}
return;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//cout<<setprecision(6)<<fixed;
ll T=1;
//cin>>T;
for(ll i=1;i<=T;i++){
solve();
}
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... |