제출 #1032696

#제출 시각아이디문제언어결과실행 시간메모리
1032696vannnnnnnn수열 (APIO14_sequence)C++14
0 / 100
155 ms896 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=1; i<=k; i++)
	{
		for(int l=1; l<n-1; l++)
		{
			for(int r=l+1; r<n; r++)
			{
				if(dp[i][r].fi<dp[i-1][l].fi+(pre[r-1]-pre[l-1])*(pre[n]-pre[r-1]))
				{
					dp[i][r].fi=dp[i-1][l].fi+(pre[r-1]-pre[l-1])*(pre[n]-pre[r-1]);
					dp[i][r].se=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
*/

컴파일 시 표준 에러 (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:44:16: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   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...