Submission #1032708

#TimeUsernameProblemLanguageResultExecution timeMemory
1032708vannnnnnnn수열 (APIO14_sequence)C++14
39 / 100
2086 ms31836 KiB
#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("%d", &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=-1;
	dp[0][0].fi=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!=-1)
				{
					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<int>res;
	while(idx!=0)
	{
		res.push_back(idx);
		idx=dp[k][idx].se;
		k--;
	}
	reverse(res.begin(), res.end());
	for(auto x:res)printf("%d ", x);
	printf("\n");
}
/*
7 3
4 1 3 4 0 2 3
*/

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:14:11: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   14 |   scanf("%d", &a[i]);
      |          ~^   ~~~~~
      |           |   |
      |           |   long long int*
      |           int*
      |          %lld
sequence.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%lld %lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
sequence.cpp:47:16: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |   res.push_back(idx);
      |   ~~~~~~~~~~~~~^~~~~
#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...