Submission #41901

#TimeUsernameProblemLanguageResultExecution timeMemory
41901festSplit the sequence (APIO14_sequence)C++14
50 / 100
438 ms3056 KiB
// fest
#include <bits/stdc++.h>	

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define FILENAME ""
#define __ fflush(stdout)

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef COMP
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#endif
}                           

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 1111, M = 201, inf = 1e9 * 2, MOD = (int)1e9 + 7;

char CH[N];

const ll INF = 1e18;

const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};

int pref[N], a[N], pr[N][M];

ll dp[N][M];

int main() {
  
	FREOPEN();
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) scanf("%d ", a + i);
	for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
	for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) dp[i][j] = -INF, pr[i][j] = -1;
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int bl = 1; bl <= k; bl++) {
			for (int j = i - 1; j >= 0; j--) {
				if (dp[j][bl - 1] == -INF) continue;
				ll now = (pref[n] - pref[i]) * 1ll * (pref[i] - pref[j]) + dp[j][bl - 1];
				if (now > dp[i][bl]) {
					dp[i][bl] = now;
					pr[i][bl] = j;
				}
			}
		}
	}
	int pos = 0;
	ll ans = -INF;
	for (int i = 1; i <= n; i++) {
		if (ans < dp[i][k]) {
			ans = dp[i][k];
			pos = i;
		}
	}
	vector<int> out;
	cout << ans << endl;
	int bl = k;
	while (pos > 0) {
		out.pb(pos);
		pos = pr[pos][bl];
		bl--;		
	}
	sort(All(out));
	for (auto i : out) printf("%d ", i);
	return 0;	
}

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:47:50: 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("%d ", a + i);
                                                  ^
#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...