Submission #23247

#TimeUsernameProblemLanguageResultExecution timeMemory
23247NurlykhanSplit the sequence (APIO14_sequence)C++14
0 / 100
1999 ms17648 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define f first #define s second #define pb push_back #define mp make_pair #define ll long long #define ld long double #define sz(v) int(v.size()) #define all(v) v.begin(), v.end() using namespace std; const int N = (int) 1000; const int M = (int) 2e6 + 10; const ll LINF = (ll) 1e18; const int INF = (int) 1e9 + 7; const double EPS = (double) 1e-9; int n, k; ll dp[2][N][N]; int a[N]; int sum(int l, int r) { return a[r] - a[l - 1]; } int main() { #define fn "balls" #ifdef witch freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen(fn".in", "r", stdin); // freopen(fn".out", "w", stdout); #endif cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } for (int i = 1; i <= k; i++) { for (int l = 1; l <= n; l++) { for (int r = l; r <= n; r++) { ll &ans = dp[i % 2][l][r]; ans = 0; for (int d = l; d < r; d++) { ans = max(ans, sum(l, d) * 1ll * sum(d + 1, r) + max(dp[1 - i % 2][l][d], dp[1 - i % 2][d + 1][r])); } } } } cout << dp[k % 2][1][n] << endl; return 0; }
#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...