Submission #134947

# Submission time Handle Problem Language Result Execution time Memory
134947 2019-07-23T13:12:59 Z wilwxk Beads and wires (APIO14_beads) C++14
0 / 100
2 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN=1e5+5;
const ll INF=1e18;
ll dp[MAXN][205];
int opt[MAXN][205];
ll soma[MAXN];
ll v[MAXN];
int n, x;

int main() {
	scanf("%d %d", &n, &x);
	for(int i=1; i<=n; i++) scanf("%lld", &v[i]);
	for(int i=1; i<=n; i++) soma[i]=soma[i-1], soma[i]+=v[i];

	dp[0][0]=0; for(int i=1; i<=x; i++) dp[0][i]=-INF;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=x; j++) {
			dp[i][j]=dp[i-1][j-1]+v[i];
			opt[i][j]=i-1;

			for(int k=0; k<i; k++) {
				ll val=dp[k][j-1]+(soma[i]-soma[k])*soma[k];
				if(val>dp[i][j]) {
					dp[i][j]=val;
					opt[i][j]=k;
				}
			}

			// printf("%d %d >> %lld // %d\n", i, j, dp[i][j], opt[i][j]);
		}
	}

	printf("%lld\n", dp[n][x]);
	vector<int> respf;
	int ind=n;
	while(opt[ind][x]!=0) {
		respf.push_back(opt[ind][x]);
		ind=opt[ind][x--];
	}
	reverse(respf.begin(), respf.end());
	for(auto cur : respf) printf("%d ", cur);
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
beads.cpp:15:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=n; i++) scanf("%lld", &v[i]);
                          ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -