| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1032717 | vannnnnnnn | 수열 (APIO14_sequence) | C++14 | 2029 ms | 31836 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
ll n, k, pre[10005], a[10005];
pair<ll, ll>dp[205][10005];
int main()
{
	ll n, k;
	scanf("%lld %lld", &n, &k);
	for(int i=1; i<=n; i++)
	{
		scanf("%lld", &a[i]);
		pre[i]=pre[i-1]+a[i];
	}
	for(int i=0; i<=k; i++)for(int j=0; j<=n; j++)dp[i][j].fi=-1e9;
	dp[0][0].fi=0;dp[0][0].se=0;
	for(int i=1; i<=k; i++)
	{
		for(int l=0; l<n-1; l++)
		{
			for(int r=l+1; r<n; r++)
			{
				if(dp[i][r].fi<dp[i-1][l].fi+(pre[r]-pre[l])*(pre[n]-pre[r]) && dp[i-1][l].fi!=-1e9)
				{
					dp[i][r].fi=dp[i-1][l].fi+(pre[r]-pre[l])*(pre[n]-pre[r]);
					dp[i][r].se=l;
//					printf("%lld %lld %d %d %d\n", dp[i][r].fi, dp[i][r].se, i, r, l);
				}
			}
		}
	}
	ll ans=0, idx;
	for(int i=1; i<=n; i++)
	{
		if(ans<dp[k][i].fi)
		{
			ans=dp[k][i].fi;
			idx=i;
		}
	}
	printf("%lld\n", ans);
	vector<ll>res;
	while(k>0)
	{
		res.push_back(idx);
		idx=dp[k][idx].se;
		k--;
	}
//	if(res.size()>1)
    reverse(res.begin(), res.end());
	for(auto x:res)printf("%lld ", x);
	printf("\n");
}
/*
7 3
4 1 3 4 0 2 3
*/
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
