CSES - APIO 2014 - Results
Submission details
Task:Split the sequence
Sender:Olli
Submission time:2019-03-24 18:13:32 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

output/cccffZTb.o: In function `calc(int, int, int)':
code.cpp:(.text+0x52): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in output/cccffZTb.o
code.cpp:(.text+0x1dd): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in output/cccffZTb.o
output/cccffZTb.o: In function `main':
code.cpp:(.text.startup+0x50): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in output/cccffZTb.o
output/cccffZTb.o: In function `_GLOBAL__sub_I_t':
code.cpp:(.text.startup+0x1b3): relocation truncated to fit: R_X86_64_PC32 against `.bss'
code.cpp:(.text.startup+0x1d1): relocation truncated to fit: R_X86_64_PC32 against `.bss'
collect2: error: ld returned 1 exit status

Code

#include <iostream>

using namespace std;

const int N = 1e3 + 1;

typedef long long ll;
typedef pair<ll, ll> pll;

ll t[N];
ll ans[N][N][201];
pll be[N][N][201];
ll sum[N];

const ll INF = 1e14;

int n;

ll calc(int a, int b, int k) {
	if(k == 0) return 0;
	if(ans[a][b][k] != 0) {
		return ans[a][b][k] - 1;
	}
	ll an = -INF;
	for(int i = a; i < b; ++i) {
		ll cur = (sum[i] - sum[a-1])*(sum[b] - sum[i]);
		cur += calc(i+1, b, k-1);
		if(cur >= an) {
			be[a][b][k] = {i, -1};
		}
		an = max(an, cur);
		
		cur = (sum[i] - sum[a-1])*(sum[b] - sum[i]);
		cur += calc(a, i, k-1);
		if(cur >= an) {
			be[a][b][k] = {i, 1};
		}
		an = max(an, cur);
	}

	ans[a][b][k] = an + 1;
	return an;
}

int main() {
	int k;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> t[i];
		sum[i] = sum[i-1] + t[i];
	}

	cout << calc(1, n, k) << "\n";
	int le = 1;
	int ri = n;
	while(k > 0) {
		cout << be[le][ri][k].first << " ";
		if(be[le][ri][k].second == 1) {
			ri = be[le][ri][k].first;
		} else {
			le = be[le][ri][k].first;
		}
		--k;
	}
	cout << "\n";
}