Submission #390006

#TimeUsernameProblemLanguageResultExecution timeMemory
390006vonatlusSplit the sequence (APIO14_sequence)C++17
33 / 100
450 ms131072 KiB
/// adil sultanov | vonat1us #pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:36777216") #include<bits/stdc++.h> #define x first #define y second #define pb push_back #define sz(x) (int) x.size() #define all(z) (z).begin(), (z).end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1e9 + 7; const int INF = 1e9 + 1e2; void fin() { #ifdef AM freopen(".in", "r", stdin); #endif } const bool flag = 0; const int N = 210; const int K = 210; ll p[N], dp[N][N][K], pr[N][N][K]; void f(int l, int r, int k) { if (k == 1) return; int cut = pr[l][r][k]; cout << cut+1 << " "; f(l, cut, k-1); } void ma1n() { int n, k; cin >> n >> k; k++; vector<int> a(n); for (int& x : a) { cin >> x; } for (int i = 0; i < n; ++i) { p[i] = (i ? p[i-1] : 0ll)+a[i]; } memset(pr, -1, sizeof(pr)); for (int i = 2; i <= k; ++i) { for (int len = 2; len <= n; ++len) { for (int l = 0; l < n; ++l) { int r = l+len-1; if (r >= n) break; for (int j = l+i-2; j < r; ++j) { ll res = dp[l][j][i-1] + (p[j]-(l ? p[l-1] : 0ll))*(p[r]-p[j]); if (res >= dp[l][r][i]) { dp[l][r][i] = res; pr[l][r][i] = j; } } } } } cout << dp[0][n-1][k] << "\n"; f(0, n-1, k); } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr), fin(); int ts = 1; if (flag) { cin >> ts; } while (ts--) { ma1n(); } 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...